使用pandas实现csv/excel sheet互相转换的方法
1.xlsxtocsv:
importpandasaspd
defxlsx_to_csv_pd():
data_xls=pd.read_excel('1.xlsx',index_col=0)
data_xls.to_csv('1.csv',encoding='utf-8')
if__name__=='__main__':
xlsx_to_csv_pd()
2.csvtoxlsx:
importpandasaspd
defcsv_to_xlsx_pd():
csv=pd.read_csv('1.csv',encoding='utf-8')
csv.to_excel('1.xlsx',sheet_name='data')
if__name__=='__main__':
csv_to_xlsx_pd()
以上这篇使用pandas实现csv/excelsheet互相转换的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。