import pandas as pd import numpy as np if __name__ == '__main__': page_1 = pd.read_excel("C:/Users/18124/Desktop/pandas/027_行操作/Students.xlsx", sheet_name="Page_001") page_2 = pd.read_excel("C:/Users/18124/Desktop/pandas/027_行操作/Students.xlsx", sheet_name="Page_002") # print(page_1.head()) # print(page_2.head()) # 数据复制 - 从左到右 students = pd.concat([page_1, page_2], axis=1) # axis=1 : 数据 - 从左到右 print(students) # 数据复制 - 从上到下 students = pd.concat([page_1, page_2]).reset_index(drop=True) # 默认axis=0 : 数据 - 从上到下 print(students) # 追加新列 students["Age"] = 25 # 初始数据 - 25 students["Age"] = np.arange(0, len(students)) # 初始数据 - 递增 print(students) # 删除列 students.drop(columns=["Age", "Score"], inplace=True) print(students) # 插入列 students.insert(1, column="Foo", value=np.repeat("foo", len(students))) print(students) # 修改列名 students.rename(columns={"Foo":"FOO", "Name":"NAME"}, inplace=True) print(students) # 去掉空值 students["ID"] = students["ID"].astype(float) # 类型转换 for i in range(5, 14): students["ID"].at[i] = np.nan print(students) students.dropna(inplace=True) # 删除空值 : 删除条件 - 每行任意一列有空值