Pandas对Excel行和列进行操作

获取行数据:

filename = '测试表.xlsx'
df = pd.DataFrame(pd.read_excel(filename))
df2 = df[(df['状态'] == '等待付款')|(df['状态'] == '已提交')]
print(df.loc[6000].tolist())//输出第6000行数据,将Series转化为list

获取列数据:

filename = '测试表.xlsx'
df = pd.DataFrame(pd.read_excel(filename))
df2 = df[(df['状态'] == '等待付款')|(df['状态'] == '已提交')]
print(df['状态'].tolist())//输出列名为‘状态’的一列数据,将Series转化为list
df = pd.DataFrame(pd.read_excel(filename))
df2 = df[(df['状态'] == '等待付款')|(df['状态'] == '已提交')]
# print(df.loc[6000].tolist())
print(df['状态'].tolist())
# DataFrame(df2).to_excel('c.xlsx', sheet_name='Sheet1', index=False, header=True)
# DataFrame(df2).to_excel('d.xlsx', sheet_name='Sheet1', header=True)

# df1= df[['所属公司', '单据编号', '表单名称','事由', '本位币', '状态']]
# df2 = df1[(df1['状态'] == '等待付款')|(df1['状态'] == '已提交')]
# df2 = df1.loc[df1['状态'] == '等待付款']

你可能感兴趣的:(pandas)