- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
csv文件中有很多站,我不知道如何使用循环来统计每个站的nan数量。目前为止我得到的就是这些,一一数一下。有人可以帮我吗,先谢谢你了。
station1= train_df[train_df['station'] == 28079004]
station1 = station1[['date', 'O_3']]
count_nan = len(station1) - station1.count()
print(count_nan)
最佳答案
我认为需要按 station
列创建索引 set_index
,过滤列以检查缺失值并最后按 sum
对其进行计数:
train_df = pd.DataFrame({'B':[4,5,4,5,5,4],
'C':[7,8,9,4,2,3],
'date':pd.date_range('2015-01-01', periods=6),
'O_3':[np.nan,3,np.nan,9,2,np.nan],
'station':[28079004] * 2 + [28079005] * 4})
print (train_df)
B C date O_3 station
0 4 7 2015-01-01 NaN 28079004
1 5 8 2015-01-02 3.0 28079004
2 4 9 2015-01-03 NaN 28079005
3 5 4 2015-01-04 9.0 28079005
4 5 2 2015-01-05 2.0 28079005
5 4 3 2015-01-06 NaN 28079005
df = train_df.set_index('station')[['date', 'O_3']].isnull().sum(level=0).astype(int)
print (df)
date O_3
station
28079004 0 1
28079005 0 2
另一个解决方案:
df = train_df[['date', 'O_3']].isnull().groupby(train_df['station']).sum().astype(int)
print (df)
date O_3
station
28079004 0 1
28079005 0 2
关于python - 如何使用loop来统计nan的个数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52184338/
首先我想说的是,我知道isNaN()和 Number.isNaN()工作。我正在阅读 David Flanagan 的 The Definite Guide,他举例说明了如何检查值是否为 NaN :
在表中,对于 skips day 列,最后一行的默认值始终是单词“last”,它不是数字。现在,结果日期显示为“NaN/NaN/NaN”,有什么方法可以将其替换为 Nil 之类的东西。 非常感谢。
我正在制作一个网站,如果用户登录,则会为用户提供一定的注销时间,其中定义了注销时间,剩余时间是从注销时间 - 服务器时间获得的。 我已经通过 PHP 获得了注销时间和服务器时间,但我想动态显示剩余时间
我有以下代码,它简单地初始化一个 UIImageView 以适应 UIImage 在当前屏幕尺寸上尽可能大的比例: CGSize mainScreenSize = [appDelegate mainS
这个问题已经有答案了: Why in numpy `nan == nan` is False while nan in [nan] is True? (1 个回答) 已关闭 3 年前。 我只是觉得这有
我有动态 JQGrid,其中一列是日期列。我从包含 URL 和日期的 feed 中获取数据。 我需要为“日期列”开发列模型,使其显示日期和超链接。但不幸的是,数据显示为 NAN/NAN/NAN (这可
我已经包含了一个演示我的问题的片段。基本上处理给了我这个错误: 调用map(NaN, -3, 3, -125, 125),返回NaN(不是数字) 我理解此消息的方式是,map 函数返回 NaN,并且由
我在下面创建的过滤器适用于 Chrome,但不适用于 Firefox。我不明白为什么。 myApp.filter('dateCustom', [ '$filter', function ($fil
虽然问题的第一部分(在标题中)之前已经回答过几次(即 Why is NaN not equal to NaN? ),但我不明白为什么第二部分会以它的方式工作(受此启发问题 How to Check l
我需要在数组中找到min和max值(不考虑可能的NaN值在这个数组中)。 这只使用 double 会很容易,但是这些 FindMin 和 FindMax 函数必须使用泛型类型。 我尝试以这种方式测
我正在开发一个屏幕,其中 UIScrollView 内只有一个 UIImageView。 UIScrollView 使用户能够固定和缩放图像。我从下面的帖子中得到了帮助。它使用 Storyboard和
尽管看到了类似的答案,但我不知道这里发生了什么。我制作了一个自定义的 UIImageview,它应该在创建后立即开始动画: class HeaderAnimator: UIImageView {
我正在寻找一个 pandas 系列并用下一个数值的平均值填充 NaN,其中:average = next numerical value/(# consecutive NaNs + 1) 到目前为止,
我有一个 mySql 表,其中有一个名为 posts 的列,该列设置为 timestamp 类型,默认为 current_timestamp。然后,我使用 php PDO 获取它的值(以及其他一些列)
我想知道以下类型的 nan 之间有什么区别。除了 NAN_macro (计算结果为 -nan(ind) 而不是 nan )的视觉差异外,它们的行为似乎都相同(根据下面的示例脚本)。 我看了一些其他的答
我为我的网页做了倒计时;它在除 Mozilla 和 IE 之外的所有浏览器上都能正常工作。 我做错了什么,我该如何解决? 下面是我的代码: ***var dt = '2018-06-14 11:59
在将 Xcode 更新到 8.3 后,我在启动时开始收到此错误:由于未捕获的异常“CALayerInvalidGeometry”而终止应用程序,原因:“CALayer 位置包含 NaN:[nan na
我正在使用 jquery 自动完成 onselect 它在不同的文本字段中显示数据。我使用 format_date() 函数在 #dob 和 #anniversery 中显示格式化日期 select:
我有一个带有 json Store 和 DateField 的网格。 Firefox 运行良好,但在 Internet Explorer 8 中无法运行。 我这样定义: function conver
我有一个错误,它在启动时使应用程序崩溃。这是我得到的错误: *** Terminating app due to uncaught exception 'CALayerInvalidGeometry'
我是一名优秀的程序员,十分优秀!