Common operations of numpy and pandas

Copyright statement: This article is an original article by the blogger, please indicate the source for reprinting https://blog.csdn.net/jingshuiliushen_zj/article/details/82857420

1. numpy:

1、np.zero
np.zeros(5)   1行5列      结果:array([ 0.,  0.,  0.,  0.,  0.])
np.zeros((2, 1))  2行1列   结果:array([[ 0.], [ 0.]])
2、矩阵乘法
np.dot
np.multiply

2. pandas

1. Read the csv file
parameters:
names, custom column name
keep_default_na=False, entries without data will be identified as 'null' instead of Nan (if the comparison operation is performed in the data processing behind Nan, an error will be reported, You need to set this property)

pdData = pd.read_csv(path, header=None, names=['Exam 1', 'Exam 2', 'Admitted'])

2. Determine whether it is empty

如果列为Nan的形式:
ss=data[data['Date_received'].notnull()]#返回不为空的
ss=data[data['Date_received'].isnull()]#返回为空的
如果列为'null'的形式(读取csv时加入了keep_default_na=False属性)
ss=data[data['Date_received']!='null']#返回不为空的
ss=data[data['Date_received']=='null']#返回为空的

3. Insert a column
pdData.insert(0, 'Ones', 1) #Insert 1 in column 0, the column name is 'Ones'