利用pandas完成CSV文件、文本文件以及Excel文件的转换。

import pandas as pd

df = pd.read_csv('国内疫情数据.csv')
# csv转excel
df.to_excel('C:\\Users\\fch\\Desktop\\excel1.xlsx',encoding='gbk')
# csv转txt
df.to_csv('C:\\Users\\fch\\Desktop\\txt.txt',encoding='gbk')
# txt转excel
with open('C:\\Users\\fch\\Desktop\\excel2.xlsx','w',encoding='gbk') as f:
    data = open('C:\\Users\\fch\\Desktop\\txt.txt',encoding='gbk')
    for line in data:
        f.write(line)