这是数据帧:
exam_data = {'name': ['Anastasia', 'Dima', 'Katherine', 'James', 'Emily', 'Michael', 'Matthew', 'Laura', 'Kevin', 'Jonas'],
'score': [12.5, 9, 16.5, np.nan, 9, 20, 14.5, np.nan, 8, 19],
'attempts': [1, 3, 2, 3, 2, 3, 1, 1, 2, 1],
'qualify': ['yes', 'no', 'yes', 'no', 'no', 'yes', 'yes', 'no', 'no', 'yes']}
labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
我试图只打印名为“尝试”的列的偶数值
有我可以使用的功能吗?
例如:
df["attempts"].even()
将^{} 用于按掩码筛选-将模2与
0
和列名进行比较:对于奇数值,通过
1
进行比较:你可以用
如果你看一下
df.attempts % 2 == 0
,你会看到它是一系列的True
和False
。然后,我们使用它作为布尔掩码来选择所需的条目,这些条目给出“0除以2时的余数”,即偶数您可以尝试以下方法:
相关问题 更多 >
编程相关推荐