python——CSV转Excel
在转换之前,事先需要将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()