我想存储所有的“坐标”(列位置和行位置),从所有的数据框条目,满足一定的条件。在我的例子中,如果值大于0.8。你知道吗
这是我的密码:
import numpy as np
import pandas as pd
randValues = np.random.rand(5,5)
df = pd.DataFrame(randValues)
df_bool = df > 0.8
colArray = np.empty([])
rowArray = np.empty([])
for dfIdx, dfCol in enumerate(df_bool):
row = dfCol.loc[dfCol['1'] == True]
if ~row.isempty():
colArray.append(dfIdx)
rowArray.append(row)
你可以试试np.where和zip
你知道吗np.哪里将返回第一个数组中的行索引和第二个数组中的列索引满足条件的索引
使用^{} 作为位置,如果不是默认索引/列值,则通过索引选择:
将
np.where
与np.column_stack
一起使用:输出:
相关问题 更多 >
编程相关推荐