【发布时间】:2021-12-31 03:21:25
【问题描述】:
通过查看这个分步教程网站,我一直在学习如何制作预测模型:https://towardsdatascience.com/step-by-step-guide-building-a-prediction-model-in-python-ac441e8b9e8b
我使用的数据是秘鲁从去年 1 月到今年 9 月的 Covid-19 病例,我想利用这些数据预测从今年 10 月到 12 月的死亡病例。 但是,“New Cases”数据类型不能转换为浮点数。所以,我添加了这个:
df = df.replace(r'^\s*$', np.nan, regex=True)
但它也不起作用......我该怎么办?
df = df[['Date', 'New Cases']]
df.head()
df = df.replace(r'^\s*$', np.nan, regex=True)
df = df.astype({"New Cases": float})
df["Date"] = pd.to_datetime(df.Date, format="%Y/%m/%d")
df.dtypes
df.index = df['Date']
plt.plot(df["New Cases"],label='2020/1/1~2021/9/30 New Cases')`
【问题讨论】:
-
使用小数点'.'而不是逗号','。如果数据来自外部来源,请替换。
标签: python string floating-point prediction