关键词:
【中文标题】TypeError:float() 参数必须是字符串或数字,而不是“期间”【英文标题】:TypeError: float() argument must be a string or a number, not 'Period' 【发布时间】:2017-08-29 14:43:53 【问题描述】:我有一个带有这样列的 pandas 数据框:
df.columns = pd.to_datetime(list(df)) #list(df) = ["2017-01", "2016-01", ...]
然后我在数据集的每一行中执行了一个插值,因为我有一些我想摆脱的 NaN。这是打印的结果:
ORIGINAL
2007-12-01 NaN
2008-12-01 NaN
2009-12-01 NaN
2010-12-01 -0.35
2011-12-01 0.67
2012-12-01 NaN
2013-12-01 NaN
2014-12-01 1.03
2015-12-01 0.37
2016-12-01 NaN
2017-12-01 NaN
Name: row1, dtype: float64
INTERPOLATION
2007-12-01 -0.350000
2008-12-01 -0.350000
2009-12-01 -0.350000
2010-12-01 -0.350000
2011-12-01 0.670000
2012-12-01 0.790219
2013-12-01 0.910109
2014-12-01 1.030000
2015-12-01 0.370000
2016-12-01 0.370000
2017-12-01 0.370000
Name: row1, dtype: float64
然后我尝试绘制插值行并得到:
TypeError: float() argument must be a string or a number, not 'Period'
整个代码:
print("ORIGINAL\n", series)
interpolation = series.interpolate(method=func, limit=10, limit_direction='both')
interpolation.plot()
print("INTERPOLATION\n",interpolation)
在我看来,错误出在系列中的时间值中,但我认为 matplotlib 应该能够处理它,所以我肯定做错了什么。提前致谢。
【问题讨论】:
【参考方案1】:这是最简单的答案,无需升级或降级熊猫。
pd.plotting.register_matplotlib_converters()
有时注册会导致另一个错误,例如 compute.use_bottleneck, use_numexpr 错误 以摆脱该调用取消注册:P
点赞:pd.plotting.deregister_matplotlib_converters()
来源:Link
【讨论】:
谢谢。绝对是 pandas 0.25 上最简单的解决方案 谢谢 - 这解决了我在使用 pandas 0.25 和 fbprophet 0.5 时遇到的具体问题。 pandas 0.25 和 fbprophet 0.3 没有发生。 太棒了,你是怎么想出来这个的。 使用您的解决方案时,我得到:TypeError: Axis must have 'freq' set to convert to Periods
。在 pandas 1.1 和 matplotlib 3.3.2 上运行。
@MarcelMotta 一旦出现此错误,只需添加以下代码:df.index = df.index.to_timestamp()
【参考方案2】:
如果我这样做,它会起作用:
plt.plot(row.index, row.values)
plt.show()
我不知道为什么...
【讨论】:
奇怪...但这解决了我的问题 pandas==0.25.3 和 fbprohpet==0.5 type(row.index) 返回:Pandas 对象的内置方法索引位于 0x000001D763176678,我无法直接绘制。上面的代码能用吗?【参考方案3】:这是 Pandas 中的一个错误,如果一切顺利,将由 next major release by August 31, 2018 修复。
目前,@J63 的解决方法必须要做。或者安装更早版本的 pandas,例如 0.20.2。
【讨论】:
或者您可以恢复到 pandas 0.20.2。这为我解决了这个问题。 你做什么 > pip install pandas==0.20.2 面临当前 0.20.3 的问题,并通过@CarlSmith 提到的降低到 0.20.2 来解决。【参考方案4】:复制了您的插值结果
df = pd.read_clipboard(header=None)
df.columns = ['Period','Value']
df['Period'] = pd.to_datetime(df['Period'])
df = df.set_index('Period')
print(df)
Value
Period
2007-12-01 -0.350000
2008-12-01 -0.350000
2009-12-01 -0.350000
2010-12-01 -0.350000
2011-12-01 0.670000
2012-12-01 0.790219
2013-12-01 0.910109
2014-12-01 1.030000
2015-12-01 0.370000
2016-12-01 0.370000
2017-12-01 0.370000
df.plot()
【讨论】:
哇,这很奇怪。 ``` print("ORIGINAL\n", row) ; row.plot() ; plt.show() ``` 给我同样的错误。因此,对于打印的值,情节有效,但对于存储的类型“期间”不...TypeError:float() 参数必须是字符串或数字,而不是“期间”
】TypeError:float()参数必须是字符串或数字,而不是“期间”【英文标题】:TypeError:float()argumentmustbeastringoranumber,not\'Period\'【发布时间】:2017-08-2914:43:53【问题描述】:我有一个带有这样列的pandas数据框:df.columns=pd.to_datetime(list(... 查看详情
TypeError:float() 参数必须是字符串或数字,而不是“SimpleImputer”
】TypeError:float()参数必须是字符串或数字,而不是“SimpleImputer”【英文标题】:TypeError:float()argumentmustbeastringoranumber,not\'SimpleImputer\'【发布时间】:2022-01-0901:25:27【问题描述】:all_data=pd.concat([train_data,test_data])average=all_data.Age.me 查看详情
TypeError:float() 参数必须是字符串或数字,而不是“时间戳”
】TypeError:float()参数必须是字符串或数字,而不是“时间戳”【英文标题】:TypeError:float()argumentmustbeastringoranumber,not\'Timestamp\'【发布时间】:2019-07-0715:07:18【问题描述】:我有一堆数据,我正在从这样的CSV文件读取到Pandas中,... 查看详情
TypeError:float() 参数必须是字符串或数字,而不是 'tuple' ,ValueError:使用序列设置数组元素
】TypeError:float()参数必须是字符串或数字,而不是\\\'tuple\\\',ValueError:使用序列设置数组元素【英文标题】:TypeError:float()argumentmustbeastringoranumber,not\'tuple\',ValueError:settinganarrayelementwithasequenceTypeError:float()参数必须是字符串或... 查看详情
TypeError: float() 参数必须是字符串或数字,而不是“函数”——Python/Sklearn
】TypeError:float()参数必须是字符串或数字,而不是“函数”——Python/Sklearn【英文标题】:TypeError:float()argumentmustbeastringoranumber,not\'function\'–Python/Sklearn【发布时间】:2018-02-2610:19:22【问题描述】:我有一个名为Flights.py的程序的... 查看详情
Pandas :TypeError: float() 参数必须是字符串或数字,而不是 'pandas._libs.interval.Interval'
】Pandas:TypeError:float()参数必须是字符串或数字,而不是\\\'pandas._libs.interval.Interval\\\'【英文标题】:Pandas:TypeError:float()argumentmustbeastringoranumber,not\'pandas._libs.interval.Interval\'Pandas:TypeError:float()参数必须是字符串或数字,而不是\'pa 查看详情
TypeError:float() 参数必须是字符串或数字,而不是“列表”和 ValueError:使用序列设置数组元素
】TypeError:float()参数必须是字符串或数字,而不是“列表”和ValueError:使用序列设置数组元素【英文标题】:TypeError:float()argumentmustbeastringoranumber,not\'list\'andValueError:settinganarrayelementwithasequence【发布时间】:2022-01-0601:22:32【问... 查看详情
我该如何解决这个错误? TypeError:float() 参数必须是字符串或数字,而不是“时间戳”
】我该如何解决这个错误?TypeError:float()参数必须是字符串或数字,而不是“时间戳”【英文标题】:HowdoIsolvethiserror?TypeError:float()argumentmustbeastringoranumber,not\'Timestamp\'【发布时间】:2021-11-1519:22:43【问题描述】:对于下面的代... 查看详情
TypeError:float() 参数必须是字符串或数字,而不是与散点图相关的“datetime.time”
】TypeError:float()参数必须是字符串或数字,而不是与散点图相关的“datetime.time”【英文标题】:TypeError:float()argumentmustbeastringoranumber,not\'datetime.time\'inrelationwithascatterplot【发布时间】:2021-10-2923:27:57【问题描述】:我创建了以下... 查看详情
LabelEncoder -- TypeError: 参数必须是字符串或数字
】LabelEncoder--TypeError:参数必须是字符串或数字【英文标题】:LabelEncoder--TypeError:argumentmustbeastringornumber【发布时间】:2020-09-1118:07:09【问题描述】:importpandasaspdfromsklearn.preprocessingimportLabelEncoderpd.set_option(\'display.max_colum 查看详情
TypeError:int() 参数必须是字符串或数字,而不是 'datetime.datetime'
】TypeError:int()参数必须是字符串或数字,而不是\\\'datetime.datetime\\\'【英文标题】:TypeError:int()argumentmustbeastringoranumber,not\'datetime.datetime\'TypeError:int()参数必须是字符串或数字,而不是\'datetime.datetime\'【发布时间】:2015-12-0302:28... 查看详情
TypeError:参数必须是字符串或数字列上的字符串或数字
】TypeError:参数必须是字符串或数字列上的字符串或数字【英文标题】:TypeError:argumentmustbeastringornumberoncolumnwithstringsthatarenumbers【发布时间】:2020-10-2713:15:40【问题描述】:我有一个包含类别的数据集。在第4列中,我有2个值(... 查看详情
Gulp TypeError:path.join 的参数必须是字符串
】GulpTypeError:path.join的参数必须是字符串【英文标题】:GulpTypeError:Argumentstopath.joinmustbestrings【发布时间】:2015-03-2406:27:49【问题描述】:我对gulp-ruby-sass有疑问。当我尝试运行watch任务并更改一些.sass文件时,会出现错误:TypeEr... 查看详情
Django TypeError int() 参数必须是字符串或数字,而不是 'QueryDict'
】DjangoTypeErrorint()参数必须是字符串或数字,而不是\\\'QueryDict\\\'【英文标题】:DjangoTypeErrorint()argumentmustbeastringoranumber,not\'QueryDict\'DjangoTypeErrorint()参数必须是字符串或数字,而不是\'QueryDict\'【发布时间】:2014-02-2605:24:14【问题... 查看详情
node-websocket-server TypeError:参数必须是字符串
】node-websocket-serverTypeError:参数必须是字符串【英文标题】:node-websocket-serverTypeError:Argumentmustbeastring【发布时间】:2011-04-2221:32:50【问题描述】:我在ubuntu上跟踪/var/log/logfile,并得到一个TypeError。适用于我的本地Mac机器/var/log/s... 查看详情
为啥在带有字符串和 NaN 的系列上得到“TypeError:'float' 类型的参数不可迭代”?
】为啥在带有字符串和NaN的系列上得到“TypeError:\\\'float\\\'类型的参数不可迭代”?【英文标题】:Whydogeta"TypeError:argumentoftype\'float\'isnotiterable"onaserieswithstringsandNaN?为什么在带有字符串和NaN的系列上得到“TypeError:\'float... 查看详情
TypeError: int() 参数必须是字符串、类似字节的对象或实数,而不是“NoneType”
】TypeError:int()参数必须是字符串、类似字节的对象或实数,而不是“NoneType”【英文标题】:TypeError:int()argumentmustbeastring,abytes-likeobjectorarealnumber,not\'NoneType\'【发布时间】:2021-12-3006:34:09【问题描述】:我正在从这个youtubeecommercet... 查看详情
TypeError [ERR_INVALID_ARG_TYPE]:“from”参数必须是字符串类型
】TypeError[ERR_INVALID_ARG_TYPE]:“from”参数必须是字符串类型【英文标题】:TypeError[ERR_INVALID_ARG_TYPE]:The"from"argumentmustbeoftypestring【发布时间】:2021-12-2409:05:33【问题描述】:我正在尝试运行黄瓜测试,但是出现以下错误TypeE... 查看详情