4
시험 df
:분할 홀수 행
import pandas as pd
df = pd.DataFrame({'A':[1,2,3,7,8,4],
'B':[4,5,6,1,4,6],
'C':[7,8,9,2,7,3],
'D':[4,5,2,1,0,6]})
df.set_index(['A','B'], inplace=True)
print (df)
C D
A B
1 4 7 4
2 5 8 5
3 6 9 2
7 1 2 1
8 4 7 0
4 6 3 6
홀수 행으로 분할 된 :
print (df.iloc[::2])
C D
A B
1 4 7 4
3 6 9 2
8 4 7 0
내가 다시 분할 필요
-df2
에 마지막 행을 df1
와 모든 다른 행 :
df1 = df.iloc[-2::2]
df2 = df.iloc[::2].iloc[:-1,:]
print (df1)
C D
A B
8 4 7 0
print (df2)
C D
A B
1 4 7 4
3 6 9 2
이중없는 더 좋은 해결책 iloc
?
고맙습니다. 아주 좋습니다. – jezrael