df_empty = pd.DataFrame(columns=['x', 'y', 'z'])Add data to an empty data box
df_new = pd.DataFrame(np.arange(6).reshape(2, 3), columns=['x', 'y', 'z'])
print(pd.concat([df_empty, df_new], axis=0))Add a new row to the existing data frame / Column , Or horizontal / Add another table vertically (axis Indicates along the longitudinal axis (axis=0) Or horizontal axis (axis=1) Directional connection )
dat_cbind = pd.concat([df1, df2], axis=1)
dat_rbind = pd.concat([df1, df3], axis=0)
dat_rbind = df1.append(df3)
Delete rows or columns ( among ,labels Is the row to delete / Column name , Give... With a list ;axis The default is 0, Refers to the deletion of a line , So delete columns When it comes to Appoint axis=1;index Directly specify the row to delete ;columns Directly specify the column to be deleted ;inplace=False, By default, the deletion operation is not Change the original data , Instead, it returns a new... After the deletion operation DataFrame;inplace=True, The original data will be deleted directly operation , And cannot return after deletion )df1.drop(labels='y', axis=1, inplace=True)
apply The object of operation is DataFrame A column of (axis=0) Or a certain line (axis=1)applymap The operation object is element level , Act on each DataFrame Every data of map The operation object is also element level , But it is right Series Call the function once for each data in the Sum up by line df_rowsum = df[['2020', '2021']].apply(lambda x: x.sum(), axis=1) Sum by columndf_colsum = df[['2020', '2021']].apply(lambda x: x.sum(), axis=0)