統計検定の
前提
Google Search Console の
* Google Search Console の
joshcarty/google-searchconsole: A wrapper for the Google Search Console API. を
本線に
- pandas の
Version python3 -m pip list | grep pandas pandas 0.21.1
参考
そもそも、
データの
* 四分位範囲 | 統計用語集 | 統計WEB
* 4-2. 箱ひげ図の
imporessions で、 箱ひげ 図を 描く
df.plot(kind='box')
で
%matplotlib inline import pandas as pd import searchconsole account = searchconsole.authenticate(service_account='./client_secrets.json') web_property = account['https://www.monotalk.xyz/'] report = web_property.query.range('today', days=-180).dimension('date').limit(50000).get() df = report.to_dataframe() df = df.loc[:,['date','impressions']] df['date'] = pd.to_datetime(df['date']) df = df.set_index('date') df.index= df.index.to_julian_date() df.plot(kind='box')
<matplotlib.axes._subplots.AxesSubplot at 0x108a80390>
imporessions の 要約統計量、 第一四分位数、 第三四分位数 を 出力
df['impressions'].describe()
で
df['impressions'].quantile(.25)
で
df['impressions'].quantile(.75)
で
# 要約統計量を出力 print("要約統計量", "\n", df['impressions'].describe()) # 25パーセンタイル 第一四分位数 Q1 = df['impressions'].quantile(.25) print("25パーセンタイル", "\n", Q1) Q3 = df['impressions'].quantile(.75) print("75パーセンタイル", "\n", Q3)
要約統計量 count 92.000000 mean 7202.989130 std 2448.724887 min 2741.000000 25% 5435.250000 50% 7170.500000 75% 9197.500000 max 11071.000000 Name: impressions, dtype: float64 25パーセンタイル 5435.25 75パーセンタイル 9197.5
%matplotlib inline import pandas as pd import searchconsole account = searchconsole.authenticate(service_account='./client_secrets.json') web_property = account['https://www.monotalk.xyz/'] report = web_property.query.range('today', days=-180).dimension('date').limit(50000).get() df = report.to_dataframe() df = df.loc[:,['date','clicks']] df['date'] = pd.to_datetime(df['date']) df = df.set_index('date') df.index= df.index.to_julian_date() df.plot(kind='box')
<matplotlib.axes._subplots.AxesSubplot at 0x108a79ba8>
clicks の 要約統計量、 第一四分位数、 第三四分位数 を 出力
# 要約統計量を出力 print("要約統計量", "\n", df['clicks'].describe()) # 25パーセンタイル 第一四分位数 Q1 = df['clicks'].quantile(.25) print("25パーセンタイル", "\n", Q1) Q3 = df['clicks'].quantile(.75) print("75パーセンタイル", "\n", Q3)
要約統計量 count 92.000000 mean 395.641304 std 158.056575 min 114.000000 25% 261.750000 50% 406.500000 75% 514.250000 max 722.000000 Name: clicks, dtype: float64 25パーセンタイル 261.75 75パーセンタイル 514.25
外れ値の 出力
【プログラマーの
を
動作が
%matplotlib inline import matplotlib.pyplot as plt account = searchconsole.authenticate(service_account='./client_secrets.json') web_property = account['https://www.monotalk.xyz/'] report = web_property.query.range('today', days=-180).dimension('date').limit(50000).get() df = report.to_dataframe() df = df.loc[:,['date','clicks']] df['date'] = pd.to_datetime(df['date']) df = df.set_index('date') df.index= df.index.to_julian_date() # 箱ひげ図 fig, ax = plt.subplots() bp = ax.boxplot(df['clicks']) ax.set_xticklabels(['clicks']) plt.title('Box plot') # Y軸のメモリのrange plt.ylim([0,1000]) plt.grid() # 描画 plt.show()
特に外れ値は
以上です。
コメント