我有 2 個 10 x 110 和 35 x 110 的表,它們都包含來自我的教授提供的指數分布函式的亂數。任務是證明統計中的中心極限定理。
我想嘗試的是:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
"importing data"
df1 = pd.read_excel(r'C:\Users\Henry\Desktop\n10.xlsx')
df2 = pd.read_excel(r'C:\Users\Henry\Desktop\n30.xlsx')
df1avg = pd.read_excel(r'C:\Users\Henry\Desktop\n10avg.xlsx')
df2avg = pd.read_excel(r'C:\Users\Henry\Desktop\n30avg.xlsx')
"plotting n10 histogram"
plt.hist(df1, bins=34)
plt.hist(df1avg, bins=11)
"plotting n30 histogram"
plt.hist(df2, bins=63)
plt.hist(df2avg, bins=11)
可以嗎,或者我是否需要將表格格式化為單列,如果是這樣,最有效的方法是什么?
uj5u.com熱心網友回復:
我懷疑您首先要展平資料框,如下圖所示。
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
N = np.random.exponential(1, [40, 5])
df = pd.DataFrame(N) # convert to dataframe
bin_edges = np.linspace(0,6,30)
plt.figure()
plt.hist(df, bins = bin_edges, density = True)
plt.xlabel('Value')
plt.ylabel('Probability density')

每個 bin 的多 (5) 種顏色的線顯示了資料框每一列的直方圖。
幸運的是,這并不難調整。您可以將資料框轉換為 numpy 陣列并將其
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/313352.html
