对于csv文件读取数据和写入数据
import os import pandas as pd data = """影片-票房-评分 你好,李焕英-46亿-9.0 四海-11亿-3.5 """ # 写入数据进入a.csv文件(系统会自动创建csv文件),写入--‘w’ with open('a.csv','w',encoding='utf-8') as file: file.write(data) print("写入成功") # 读取a.csv文件(无间隔符的读取),读取--‘r’ with open('a.csv','r',encoding='utf-8') as file: file.read() # pandas对于有间隔符数据的读取,提取列用usecols属性,sep代表间隔符的样式 df=pd.read_csv('a.csv', sep='-') print(df)