- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想使用 pandas 中的 fillna 命令来估算数据帧。这是我的代码片段:
import glob
import pandas as pd
files=glob.glob("IN.201*.csv")
i=0
n=1
#the while loops are for reading and writing different subsets of the table into
#different .txt files:
while i<15:
j=0
while j<7:
dfs=[]
m=1
#for loop over only one file for testing:
for file in files[:1]:
z=i+1
#reading subset of the dataframe:
k=float(68.109375)+float(1.953125)*i
k1=float(68.109375)+float(1.953125)*z
l=float(8.0)+float(4)*j
l1=float(8.0)+float(4)*(j+1)
df=pd.read_csv(path+file).query( '@k <= lon < @k1 and @l < lat <= @l1')[['lon','lat','country','avg']]
#renaming columns in df:
df.rename(columns={"avg":"Day"+str(m)}, inplace=True)
#print(df)
m=m+1
dfs.append(df)
#imputation:
df_final=dfs[0].fillna(method='bfill', axis='columns', inplace=True).fillna(method='ffill', axis=1, inplace=True)
#writing to a txt file:
with open('Region_'+str(n), 'w+') as f:
df_final.to_csv(f)
n=n+1
j=j+1
i=i+1
错误:
Traceback (most recent call last):
File "imputation_test.py", line 42, in <module>
df_final=dfs[0].fillna(method='bfill', axis='columns', inplace=True).fillna(
method='ffill', axis=1, inplace=True)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python36\lib\site-
packages\p
andas\core\frame.py", line 3787, in fillna
downcast=downcast, **kwargs)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\generic.py", line 5359, in fillna
raise NotImplementedError()
NotImplementedError
代码的动机:
我本质上想将 .csv 文件读入由该表的不同子集组成的多个数据帧(因此我使用了所有循环),以便重新排列和分割 .csv 文件(实际上我想对多个 .csv 文件执行此操作)转换为更合适的格式。然后我想使用 fillna 命令沿着列轴填充缺失的数据。
该代码的结构是为了读取多个 .csv 文件,因此具有诸如“df=[ ]”和“for 循环”之类的不必要的命令,但为了简化目的,我首先尝试了此代码,以确保我出现这个错误。请随时询问有关此错误的更多信息。谢谢!
最佳答案
dfs = dfs.bfill(axis=1).ffill(axis=1)
部分问题在于 inplace=True
和链接方法。 inplace=True
返回一个空对象,因此没有任何东西可以调用链式方法。第二部分是 fillna(method='ffill')
可以缩短为 ffill()
。
关于python - pandas.dataframe.fillna : NotImplementedError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51064157/
我正在使用以下 gem 作为编辑器。 gem "wysihat-engine", "~> 0.1.13" 当我运行“rails generate wysihat”时,它会生成所有图像文件,但无法生成迁
我的Scrapy代码无效。我正在尝试抓取论坛,但收到错误。 这是我的代码: import scrapy, time class ForumSpiderSpider(scrapy.Spider):
为什么 gevent 会抛出这个错误?在 ipython、ubuntu 13 中运行它 In [1]: from gevent import monkey In [2]: monkey.patch_a
如何将 instance 属性标记为未在基类中实现? (与讨论将 class 属性标记为未实现的 this 问题不同,但也许我没有正确理解基类...) 例如我想要类似的东西 class Base():
系统信息 python 3.8.7 操作系统 11.1(大苏尔) 通过 brew install python@3.8 安装的 Python 要在 Big Sur 和最有可能的旧版本上重现: impo
我正在阅读一篇关于布隆过滤器的文章,https://en.wikipedia.org/wiki/Bloom_filter ,其中一个表达式是为散列函数的最佳数量导出的。我想重现 m 的简化情况的计算=
我正在尝试使用 ActiveJob将诸如电子邮件调度之类的作业排队,但我得到一个 NotImplementedError (Use a queueing backend to enqueue jobs
我需要实现一个具有数百种方法的接口(interface)(ResultSet)。 现在,我将只实现这些方法的一个子集,抛出 NotImplementedError为其他人。 在 Java 中,我找到了
这是我的代码: package example object Lists { def max(xs: List[Int]): Int = { if(xs.isEmpty){
我正在使用 django 和 Google App Engine。我无法确定错误来自哪里,因为如果我在本地使用它,我的网站就会正常运行。在我将其部署到 GAE 上之后,它工作正常,但是当使用 goog
import torch import torch.nn as nn device = torch.device('cuda' if torch.cuda.is_available() else 'c
我的 scrapy 代码不工作,我不知道!我想抓取宜家网站,我首先设计了一个 CrawlSpider,它不够具体,无法检索网页的每个链接。所以我设计了一个带有 yield 请求方法的基本 Spider
是为了提醒你自己和你的团队正确实现类(class)吗?我没有完全使用这样的抽象类: class RectangularRoom(object): def __init__(self, widt
尝试在本地预编译 Assets 时出现以下问题 RAILS_ENV=production bundle exec rake assets:precompile rake aborted! Sprock
在我的 Rails 应用程序 (4.2.4) 中,我一直在尝试让异步邮件发送工作。 我安装了 delay_job 作为我的队列适配器,并在几个地方将它设置为适配器:config/application
这个问题在这里已经有了答案: Jupyter Notebook with Python 3.8 - NotImplementedError (4 个答案) 关闭 3 年前。 尝试在本地主机上构建 j
我在 azure 上上传时遇到问题 https://learn.microsoft.com/pl-pl/azure/machine-learning/how-to-access-data-intera
我想使用 pandas 中的 fillna 命令来估算数据帧。这是我的代码片段: import glob import pandas as pd files=glob.glob("IN.201*.cs
服务器JSON使用retrofit2和rxjava2进行数据解析。转到CompanyAdapter类时,数据获取并成功存储在List中,然后给出上述错误。 MainActivity.kt priva
我想使用 pandas 中的 fillna 命令来估算数据帧。这是我的代码片段: import glob import pandas as pd files=glob.glob("IN.201*.cs
我是一名优秀的程序员,十分优秀!