我在python中有一個數據框,我試圖僅從列中的有效值及其索引(例如,如何在python中創建一個數據框的索引和值的列表
index A B C D
Grade 50 50
Date 50
Time 50 50
Score 50
Height 50
我想要的清單,是以[柱,INDEX_NAME,值]它看起來像這樣
[A,Date,50,Score,50]
[B,Height,50]
[C,Grade,50,Time,50]
到目前爲止,我得到的是
for column in df:
df.loc[df[column] >= 50]
matched_list = (df.loc[df[column] >= 50])
full_list = [column] + list(matched_list.index.values) + [x for x in df[column] if x >= 50]
但是這給了我這個:
[A,Date,Score,50.50]
[B,Height,50]
[C,Grade,Time,50,50]
Can anyo ne幫助,謝謝!
想用熊貓嗎? – BlooB