6
을 dataframe. 두 번째 인덱스의 수준 수는 첫 번째 인덱스의 값에 따라 다릅니다. 나는 pandas multi index documentation을 훑어 보았지만 그렇게하는 것을 찾을 수 없었다. 예를 들어액세스 마지막 요소 I는 첫 번째 인덱스의 모든 값에 대한 두 번째 인덱스 <strong></strong> 마지막 요소에 액세스하려는 <code>multi index</code> 팬더 dataframe에서
, 아래의 데이터 프레임 :
arrays = [ ['bar', 'bar', 'baz', 'foo', 'foo', 'foo', 'qux'],
['one', 'two', 'one', 'one', 'two', 'three', 'one']]
tuples = list(zip(*arrays))
index = pd.MultiIndex.from_tuples(tuples, names=['first', 'second'])
df = pd.DataFrame(np.random.randn(7, 3), index=index, columns=['A', 'B', 'C'])
df
A B C
first second
bar one 0.289163 -0.464633 -0.060487
two 0.224442 0.177609 2.156436
baz one -0.262329 -0.248384 0.925580
foo one 0.051350 0.452014 0.206809
two 2.757255 -0.739196 0.183735
three -0.064909 -0.963130 1.364771
qux one -1.330857 1.881588 -0.262170
나는 싶어 :
A B C
first second
bar two 0.224442 0.177609 2.156436
baz one -0.262329 -0.248384 0.925580
foo three -0.064909 -0.963130 1.364771
qux one -1.330857 1.881588 -0.262170
내가 작업을 오전 dataframes
는 10M
이상의 라인을 가지고 그래서 명시 적 루프를 피하려고.
당신은 (= '첫 번째'레벨)'할 df.groupby 수를 마지막으로()' – EdChum