1
如果這個問題太天真,請提前道歉。我是Python的新手。我試圖對我的數據框的兩列執行t檢驗。只有在同一數據幀中的另一列對列進行分組後,才能進行t檢驗。按小組分組給熊貓系列/數據框
我處理這樣的事情:
rand_array = np.random.randint(low=10, high=30, size=9)
rand_array2 = np.random.randint(low=10, high=30, size=9)
d = {'key1':[0,0,1,0,1,1,1,0,1], 'key2': rand_array, 'key3': rand_array2}
df1 = pd.DataFrame(d)
print df1
我得到的輸出是:
key1 key2 key3
0 0 20 18
1 0 22 16
2 1 21 26
3 0 21 13
4 1 11 21
5 1 23 10
6 1 17 29
7 0 13 25
8 1 24 29
然後,我按鍵1
g1 = df1.groupby('key1')
print g1.groups
>>> {0: Int64Index([0, 1, 3, 7], dtype='int64'), 1: Int64Index([2, 4, 5, 6, 8], dtype='int64')}
我想執行一個基本上是0:Int64Index([0,1,3,7],dtype ='int64')與1:Int64Index([2,4,5,6,8],dtype ='int64')的t檢驗。
這可能嗎?
謝謝!
這在['scipy.stats.ttest_ind'(https://docs.scipy.org/doc還實施/scipy-0.14.0/reference/generated/scipy.stats.ttest_ind.html)和'equal_var = False'。 – unutbu
謝謝你們倆。它現在工作:) – tester777