我有一个这样的系列
s = pd.Series({'a': False, 'b': True, 'c': False, 'd': True, 'e': False})
>> s
a False
b True
c False
d True
e False
dtype: bool
有没有一种方法可以巧妙地把真实的地方的名字提取出来,留在熊猫或小矮人的身体里,而不必回到普通的Python身上
目前我正在使用:
sdict = s.to_dict()
for item in list(sdict):
if sdict[item] == True:
print (item, end=" ")
>> b d
将^{} 与
s.index
一起使用:用
np.where
的有点过于复杂的解决方案,为了好玩:相关问题 更多 >
编程相关推荐