Python 将两列数据帧转换为多索引系列
如何打开此数据帧:Python 将两列数据帧转换为多索引系列,python,pandas,dataframe,series,Python,Pandas,Dataframe,Series,如何打开此数据帧: In [1]: df Out[1]: col_name C P FULL count_x 1 5 count_y 2 6 CALIB count_x 3 7 count_y 4 8 在本系列中: In [2]: s Out[2]: C FULL count_x 1 count_y 2 CALIB count_x 3
In [1]: df
Out[1]:
col_name C P
FULL count_x 1 5
count_y 2 6
CALIB count_x 3 7
count_y 4 8
在本系列中:
In [2]: s
Out[2]:
C FULL count_x 1
count_y 2
CALIB count_x 3
count_y 4
P FULL count_x 5
count_y 6
CALIB count_x 7
count_y 8
Python 3,Pandas 1.1.1.两个级别都使用:
s = df.unstack([0,1])
print (s)
C FULL count_x 1
count_y 2
CALIB count_x 3
count_y 4
P FULL count_x 5
count_y 6
CALIB count_x 7
count_y 8
dtype: int64
另一个想法与另一个过程有关,但有必要进行另一个过程,并且:
尝试新事物
out = pd.concat({x : df[x] for x in df.columns})
Out[113]:
col_name col_name1
C FULL count_x 1
count_y 2
CALIB count_x 3
count_y 4
P FULL count_x 5
count_y 6
CALIB count_x 7
count_y 8
dtype: int64
我总是忘了拆堆栈!
out = pd.concat({x : df[x] for x in df.columns})
Out[113]:
col_name col_name1
C FULL count_x 1
count_y 2
CALIB count_x 3
count_y 4
P FULL count_x 5
count_y 6
CALIB count_x 7
count_y 8
dtype: int64