滤波行只有一个列中的一个具有值和创建列以在熊猫中附加记分卡
我的目标是过滤行,其中只有一列中的一个没有NAN的值。一旦我过滤了这些行,我想为每列发生多少个实例创建一个记分卡。
示例输入:
index id pass shoot flick through-ball
22450 0123 NaN NaN NaN 600
22451 6565 NaN NaN NaN 625
22452 1212 123 NaN 454 NaN
22453 0101 NaN NaN 119 NaN
22454 1234 NaN 056 98 NaN
过滤的预期结果:
index id pass shoot flick through-ball
22450 0123 NaN NaN NaN 600
22451 6565 NaN NaN NaN 625
22453 0101 NaN NaN 119 NaN
最终预期输出表:
actions unique_count
pass 0
shoot 0
flick 1
through-ball 2
My goal is to filter rows where only one of the columns has a value that is not NaN. Once I have those rows filtered, I want to create a scorecard for how many instances this happened per column.
Example input:
index id pass shoot flick through-ball
22450 0123 NaN NaN NaN 600
22451 6565 NaN NaN NaN 625
22452 1212 123 NaN 454 NaN
22453 0101 NaN NaN 119 NaN
22454 1234 NaN 056 98 NaN
Expected result from filtering:
index id pass shoot flick through-ball
22450 0123 NaN NaN NaN 600
22451 6565 NaN NaN NaN 625
22453 0101 NaN NaN 119 NaN
Final expected output table:
actions unique_count
pass 0
shoot 0
flick 1
through-ball 2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
输出:
output:
要过滤数据框,我们可以按列计算非NAN值,
我们可以循环列以获取每个列中的唯一值计数
To filter the dataframe, we can count the not nan value along columns
We can loop the columns to get unique value count in each column
我们可以对其进行过滤
,然后
count
We can filter it
Then
count