Pandas库笔记

1
import pandas as pd

缺失值处理

判断nan

1
2
pd.isnull()
pd.notna()

返回一个布尔矩阵,显示nan位置。

删除行列操作

若要使用数字调用索引,需要调用df.index行属性和df.columns列索引

1
2
pd.drop(df.index[])
pd.drop(df.columns[])
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
def document_merge() -> dict:
data = {}
#完善代码

import pandas as pd

xlsx = pd.read_excel("/home/project/2022_january.xlsx")
new_xlsx = xlsx.set_axis(xlsx.iloc[3],axis=1)
new_xlsx.drop(new_xlsx.columns[0:2],axis=1,inplace=True)
new_xlsx.drop(new_xlsx.index[0:4],axis=0,inplace=True)
new_xlsx.reset_index(drop=True,inplace=True)
print(new_xlsx)

return data

document_merge()