1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > 工作中一个简单python数据处理-统计csv文件并画柱状图

工作中一个简单python数据处理-统计csv文件并画柱状图

时间:2022-07-12 01:19:28

相关推荐

工作中一个简单python数据处理-统计csv文件并画柱状图

工作中一个简单python数据处理

工作中需要parsing一些短信数据,会有接口直接将数据导入到csv文件,但是报告时需要统计csv文件中数据频率,所以写了一个python脚本做一些简单处理。

流程:

1.读取相应文件夹及相应csv文件

2.取出csv文件相应列进行统计

3.使用pyplot绘制柱状图

import osimport csv import matplotlib.pyplot as pltdata_path = 'D:\csv\\'file_list = os.listdir(data_path)dictionary = {}dbig150 = {}total = 0for f in file_list:csv_reader = csv.reader(open(data_path+str(f)))i = 0for line in csv_reader:if i == 0:i = 1continuedata = line[7]cnt = int(line[8])total += cntx = int(data[9:])if(x<0):print("x=",x)if(x>150):if x not in dbig150:dbig150[x] = cntelse:dbig150 += cntx = 150if x not in dictionary:dictionary[x] = cntelse:dictionary[x] += cnttemp = sorted(dbig150)print("total=",total)sorted(dictionary.keys())plt.bar(list(dictionary.keys()),dictionary.values(),color='g')plt.show()

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。