Pandas14——excel【行】增删查改

excel原始数据
#导入原始数据
import pandas as pd
Page01=pd.read_excel("D:\\python_pandas\\sample\\demo16\\Students.xlsx",sheet_name="Page_001")
Page02=pd.read_excel("D:\\python_pandas\\sample\\demo16\\Students.xlsx",sheet_name="Page_002")
合并表格
#合并
#ignore_index = True, index重新排序.
stu=Page01.append(Page02,ignore_index=True)
追加一行
#追加一行
person = pd.Series({"ID":41,"Name":"Battery","Score":99})
stu=stu.append(person,ignore_index=True)
插入一行
#插入一行
#reset_index():重置 index。drop=True丢弃原来的列
person = pd.Series({"ID":42,"Name":"Bad","Score":60})
stu=stu[:40].append(person,ignore_index=True).append(stu[40:]).reset_index(drop=True)
#修改某单元格数据
stu.at[40,"Score"] = 66
修改某单元格数据
替换
#替换一行
person = pd.Series({"ID":40,"Name":"Apple","Score":77})
stu.iloc[39] = person
删除
#删除一行
stu.drop(36,inplace=True)
根据条件删除某行
#删除name为空值的行
condition  = (stu["Name"]=='')
stu.drop(stu[condition].index,inplace=True)

你可能感兴趣的:(Pandas14——excel【行】增删查改)