本文主要是介绍python中csv处理一二,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1.删除csv首行(属性)
d = open('filtered_data.csv').readlines() d[0] = '' with open('new_filtered_data.csv', 'w') as f:f.writelines(d)
2.删除csv第一列(序号)
import csv d_new=open('new_filtered_data.csv','r') df=csv.reader(d_new) data = [] for row in df:data.append(row[1:])
3.读取csv为list
import csv d_new=open('new_filtered_data.csv','r') df=csv.reader(d_new) data=list(df)
4.读取csv为DataFrame
f = open('filtered_data.csv', encoding='GBK') df = pd.read_csv(f) data = pd.DataFrame(df.iloc[:, 1:].values)
这篇关于python中csv处理一二的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!