import pandas as pd
pd.read_csv(fileName, encoding='utf-8') # 读取csv
pd.to_csv(fileName) # 保存文件,fileName为文件路径,可以是相对路径or绝对路径
pd.to_csv(fileName, index=0) # 保存到文件时,不要保存索引
DataFrame插入行 or 合并2个DataFrame
# new_list为即将插入到df1的二维列表
a1=['a1','b1','c1']
a2=['a2','b2','c2']
new_list.append(a1)
new_list.append(a2)
df1 = pd.read_csv(fileName, encoding='utf-8')
df2 = pd.DataFrame(new_list, columns=df1.columns)
# 方法1
after = pd.concat(df2, df1, ignore_index=True)
after.to_csv(fileName, index=0)
# 方法2
after = df2.append(df1.iloc[:], ignore_index=True)
after.to_csv(fileName, index=0)