pandas读取excel文件,并取值
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/66b554a2bfcf2b902e3daefdb655a305.png)
import pandas as pd
df = pd.read_excel('goods_info.xlsx', index_col=0, header = 0)
print(df)
print('-'*50)
goods = df.columns
banana = df['banana']
print(banana)
grape = df['grape']
print(grape)
print('-'*50)
s1 = df.loc['price','banana']
s2 = df.loc['price','grape']
print(s1)
print(s2)
print('-'*50)
s3 = df.iloc[0,1]
s4 = df.iloc[0,3]
print(s3)
print(s4)
print('-'*50)
df.to_excel('goods_info.xlsx')
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/85531e9d7b4e2bde251202ab0992f1e3.png)
pandas保存csv文件
import pandas as pd
result={'credit':[], 'name':[],'product':[]}
out = pd.DataFrame(result)
out.to_csv(r"D:\Work\result.csv", index=False, header=False, mode="a")