python处理csv

几行简单的代码,用了pandas库处理csv,基于python2.7

import csv
import pandas as pd
path='D:\Users\yale\Desktop\demo.csv'
csvFile2 = open('D:\Users\yale\Desktop\demo2.csv','ab+')
writer = csv.writer(csvFile2)
with open(path)as file:
    data=pd.read_csv(file)
    for d in range(4768):
    	a = data.ix[d,0]
    	b = a.split(' ')
    	c = b[0:3]
    	add_info = [c]
    	writer.writerow(add_info)

需要注意的就是’ab+’,表示追加写入,和’a+'的区别就是ab+写入后没有空行,a+写入是有空行的

你可能感兴趣的:(python处理csv)