python——CSV轉Excel
阿新 • • 發佈:2019-05-03
install module open utf-8 med pre 轉換 之前 read
在轉換之前,事先需要將csv文件另存為此格式
import pandas as pd def csv_to_xlsx_pd(): csv = pd.read_csv(r‘C:\Users\Jery\Desktop\guazi1.csv‘, encoding=‘utf-8‘) csv.to_excel(r‘C:\Users\Jery\Desktop\guazi1.xlsx‘, sheet_name=‘data‘) if __name__ == ‘__main__‘: csv_to_xlsx_pd()
若轉換出現 ModuleNotFoundError: No module named ‘openpyxl‘
請先在cmd裏 pip install openpyxl
import pandas as pd import openpyxl def csv_to_xlsx_pd(): csv = pd.read_csv(r‘C:\Users\Jery\Desktop\guazi1.csv‘, encoding=‘utf-8‘) csv.to_excel(r‘C:\Users\Jery\Desktop\guazi1.xlsx‘, sheet_name=‘data‘) if __name__ == ‘__main__‘: csv_to_xlsx_pd()
python——CSV轉Excel