用pandas库对csv文件中的文本数据进行分析处理
#数据分析 import pandas import csv old_path = r'd:\2000W\200W-400W.csv' f = open(old_path,'r',encoding='utf-8') data = pandas.read_csv(f) # print(data) num = int(data.describe().ix[0,0]) # print(num) # print(num) #遍历出所有行 # print("---------遍历出所有行-------") # for i in range(num): # record = data.ix[i,:] # print(record) # print(record['Name']) # print(record['CtfId']) # print(record['Mobile']) # print(record['EMail']) # print(record['Birthday']) new_path = r'd:\n.csv' new_file = open(new_path,'w',encoding='utf-8') writer = csv.writer(new_file) writer.writerow(('Name','CtfId','Mobile','EMail','Birthday')) for i in range(num): record = data.ix[i,:] Name = record['Name'] CtfId = record['CtfId'] Mobile = record['Mobile'] EMail = record['EMail'] Birthday = record['Birthday'] writer.writerow((record['Name'],record['CtfId'],record['Mobile'],record['EMail'],record['Birthday'])) print("保存完毕")
本文来自博客园,作者:江雪独钓翁,转载请注明原文链接:https://www.cnblogs.com/zhouwp/p/7560852.html