[英]Get Row and Column name of a specific cell in DataFrame
reqd_Index = df[df['id']== True].index.tolist()
print(reqd_Index)
假设您有以下 dataframe:
df = pd.DataFrame({'AST': {'id': False, 'REB': False, 'FG3a': False},
'BLK': {'id': False, 'REB': False, 'FG3a': False},
'DREB': {'id': False, 'REB': True, 'FG3a': False}})
AST BLK DREB
id False False False
REB False False True
FG3a False False False
melt
DataFrame 并返回您感兴趣的行:true = df.melt(ignore_index=False)
true[true['value']]
variable value
REB DREB True
print
,你可以这样做:true = df.melt(ignore_index=False)
true = true[true['value']]
[print(x,y) for (x,y) in zip(true.index, true['variable'])]
REB DREB
output in an array
中,那么你可以这样做:true = df.melt(ignore_index=False).reset_index()
true[true['value']].drop('value', axis=1).values
array([['FG3a', 'BLK'],
['REB', 'DREB']], dtype=object)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.