6.数据清洗之excel文件读写

说明:

*使用read_excel读取,读取后的结果为dataframe格式

*读取excel文件和csv文件参数大致一致,但要考虑工作表sheet页

*参数较多,可以自行控制,但很多时候用默认参数

*读取excel时,注意编码,常用编码为utf-8、gbk、gbk2312和gb18030等

*使用to_excel方法快速保存为xlsx格式
————————————————
 

#有多个工作页时,指定哪个工作簿
#sheet_name='你的工作页名字'或sheet_name='0'或'1'
df=pd.read_excel('Vehicle No.0_Fragment No.0.xlsx',sheet_name='sheet1')
df.head(5)
df=pd.read_excel('Vehicle No.0_Fragment No.0.csv',encoding='utf-8',nrows=10)
import os 
os.getcwd()

df.to_excel('a.xlsx',sheet_name='sheet1',index=False,encoding='utf-8',)
发布了65 篇原创文章 · 获赞 20 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/l641208111/article/details/104224354