2016-11-01   python   math   stat 

PythonでCSVファイルをもとにヒストグラムを描く例

結果

コード

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

df = pd.read_csv("mmchars.csv", names=['Vol', 'chars'])
print(df.describe())
plt.hist(df['chars'], bins=20)
plt.title('結城メルマガ文字数分布')
plt.xlabel('文字数')
plt.ylabel('度数')
plt.show()

データ

結城メルマガVol.000〜Vol.240のメール本文の文字数(バイト数ではない)。

mm000.txt,8231
mm001.txt,14454
mm002.txt,14082
mm003.txt,16462
mm004.txt,14130
mm005.txt,16437
mm006.txt,16990
mm007.txt,15509
mm008.txt,15531
mm009.txt,17740
mm010.txt,16487
mm011.txt,15334
mm012.txt,10351
mm013.txt,14522
mm014.txt,15055
mm015.txt,7915
mm016.txt,16494
mm017.txt,13841
mm018.txt,7356
mm019.txt,7566
mm020.txt,13459
mm021.txt,10843
mm022.txt,12727
mm023.txt,8034
mm024.txt,9468
mm025.txt,7492
mm026.txt,6480
mm027.txt,13516
mm028.txt,7488
mm029.txt,4946
mm030.txt,8839
mm031.txt,7511
mm032.txt,13480
mm033.txt,5786
mm034.txt,2903
mm035.txt,7636
mm036.txt,7525
mm037.txt,12532
mm038.txt,14585
mm039.txt,12604
mm040.txt,15285
mm041.txt,16465
mm042.txt,13728
mm043.txt,10796
mm044.txt,17395
mm045.txt,16976
mm046.txt,8628
mm047.txt,9220
mm048.txt,8824
mm049.txt,13565
mm050.txt,7451
mm051.txt,4682
mm052.txt,7313
mm053.txt,11538
mm054.txt,8179
mm055.txt,11924
mm056.txt,6777
mm057.txt,13646
mm058.txt,10460
mm059.txt,8384
mm060.txt,6191
mm061.txt,7149
mm062.txt,7945
mm063.txt,8578
mm064.txt,7743
mm065.txt,8247
mm066.txt,7457
mm067.txt,8858
mm068.txt,14428
mm069.txt,8556
mm070.txt,9161
mm071.txt,13508
mm072.txt,10144
mm073.txt,8163
mm074.txt,10833
mm075.txt,7759
mm076.txt,8018
mm077.txt,8660
mm078.txt,5486
mm079.txt,6818
mm080.txt,7605
mm081.txt,6214
mm082.txt,1995
mm083.txt,9451
mm084.txt,8781
mm085.txt,8920
mm086.txt,6585
mm087.txt,5736
mm088.txt,9100
mm089.txt,7270
mm090.txt,10341
mm091.txt,7589
mm092.txt,13470
mm093.txt,8081
mm094.txt,7607
mm095.txt,6856
mm096.txt,7787
mm097.txt,8000
mm098.txt,12908
mm099.txt,9347
mm100.txt,14224
mm101.txt,11506
mm102.txt,7099
mm103.txt,12781
mm104.txt,9465
mm105.txt,12833
mm106.txt,9674
mm107.txt,10795
mm108.txt,10619
mm109.txt,14229
mm110.txt,9783
mm111.txt,7904
mm112.txt,7974
mm113.txt,9687
mm114.txt,8369
mm115.txt,10825
mm116.txt,7916
mm117.txt,10737
mm118.txt,10152
mm119.txt,10250
mm120.txt,7858
mm121.txt,8344
mm122.txt,2024
mm123.txt,12935
mm124.txt,10125
mm125.txt,10991
mm126.txt,11123
mm127.txt,13345
mm128.txt,14293
mm129.txt,9355
mm130.txt,13835
mm131.txt,14785
mm132.txt,10362
mm133.txt,9051
mm134.txt,8388
mm135.txt,9675
mm136.txt,8453
mm137.txt,9190
mm138.txt,10176
mm139.txt,13054
mm140.txt,9007
mm141.txt,9986
mm142.txt,10325
mm143.txt,10928
mm144.txt,1490
mm145.txt,13259
mm146.txt,10426
mm147.txt,11077
mm148.txt,13702
mm149.txt,11405
mm150.txt,9548
mm151.txt,12494
mm152.txt,11206
mm153.txt,10169
mm154.txt,9722
mm155.txt,11559
mm156.txt,9971
mm157.txt,10967
mm158.txt,11294
mm159.txt,10459
mm160.txt,10097
mm161.txt,15262
mm162.txt,13561
mm163.txt,11140
mm164.txt,11593
mm165.txt,11216
mm166.txt,9814
mm167.txt,11782
mm168.txt,10130
mm169.txt,10461
mm170.txt,8871
mm171.txt,10597
mm172.txt,12175
mm173.txt,13200
mm174.txt,11573
mm175.txt,11276
mm176.txt,11172
mm177.txt,14303
mm178.txt,14535
mm179.txt,13247
mm180.txt,12741
mm181.txt,10550
mm182.txt,10964
mm183.txt,11033
mm184.txt,14766
mm185.txt,12669
mm186.txt,14352
mm187.txt,14641
mm188.txt,15121
mm189.txt,12040
mm190.txt,13118
mm191.txt,13265
mm192.txt,11740
mm193.txt,18827
mm194.txt,14231
mm195.txt,15497
mm196.txt,12238
mm197.txt,12647
mm198.txt,11607
mm199.txt,10858
mm200.txt,14533
mm201.txt,15885
mm202.txt,12640
mm203.txt,13756
mm204.txt,14136
mm205.txt,13962
mm206.txt,14768
mm207.txt,12641
mm208.txt,11490
mm209.txt,13583
mm210.txt,14646
mm211.txt,13347
mm212.txt,13908
mm213.txt,14293
mm214.txt,12897
mm215.txt,14874
mm216.txt,13422
mm217.txt,13006
mm218.txt,15435
mm219.txt,14671
mm220.txt,12788
mm221.txt,13579
mm222.txt,13044
mm223.txt,14225
mm224.txt,12877
mm225.txt,14755
mm226.txt,12875
mm227.txt,11566
mm228.txt,13163
mm229.txt,12351
mm230.txt,12260
mm231.txt,14240
mm232.txt,13414
mm233.txt,13139
mm234.txt,11981
mm235.txt,12376
mm236.txt,13611
mm237.txt,13957
mm238.txt,12853
mm239.txt,13878
mm240.txt,16180

実行

$ python3 mmchars.py
              chars
count    241.000000
mean   11203.381743
std     3089.392742
min     1490.000000
25%     8839.000000
50%    11216.000000
75%    13565.000000
max    18827.000000

参照

[Python]Matplotlibでヒストグラムを描画する方法

 2016-11-01   python   math   stat