python - Pandas 导入错误“ImportError: cannot import name 'FrameOrSeriesUnion' from 'pandas._typing'”
问题描述
当我尝试 import pandas as pd 时,它给出了这个错误。我不能导入熊猫。我重新安装了 pandas,但它是一样的。我尝试运行 promt 和 jupyter notebook。我正在使用 conda env 和 pycharm。我尝试了另一台电脑,但它是一样的。也许有些东西不见了?我应该怎么办 ?这是我的代码:
import pandas as pd
from neuralprophet import NeuralProphet
from matplotlib import pyplot as plt
import pickle
df = pd.read_csv('weatherAUS.csv')
df.head()
df.Location.unique()
df.columns
melb = df[df['Location']=='Melbourne']
melb['Date'] = pd.to_datetime(melb['Date'])
melb.head()
plt.plot(melb['Date'], melb['Temp3pm'])
plt.show()
melb['Year'] = melb['Date'].apply(lambda x: x.year)
melb = melb[melb['Year']<=2015]
plt.plot(melb['Date'], melb['Temp3pm'])
plt.show()
data = melb[['Date', 'Temp3pm']]
data.dropna(inplace=True)
data.columns = ['ds', 'y']
data.head()
#model eğitme
m = NeuralProphet()
model = m.fit(data, freq='D', epochs=1000)
#forecast
future = m.make_future_dataframe(data, periods=900)
forecast = m.predict(future)
forecast.head()
plot1 = m.plot(forecast)
plt2 = m.plot_components(forecast)
#save model
with open('saved_model.pkl', "wb") as f:
pickle.dump(m, f)
del m
with open('saved_model.pkl', "rb") as f:
m = pickle.load(f)
future = m.make_future_dataframe(data, periods=900)
forecast = m.predict(future)
forecast.head()
plot1 = m.plot(forecast)
错误:
Traceback (most recent call last):
File "C:/Users/Lenovo/PycharmProjects/pythonProject/a.py", line 1, in <module>
import pandas as pd
File "C:\Users\Lenovo\anaconda3\envs\pythonProject\lib\site-packages\pandas\__init__.py", line 51, in <module>
from pandas.core.api import (
File "C:\Users\Lenovo\anaconda3\envs\pythonProject\lib\site-packages\pandas\core\api.py", line 14, in <module>
from pandas.core.algorithms import factorize, unique, value_counts
File "C:\Users\Lenovo\anaconda3\envs\pythonProject\lib\site-packages\pandas\core\algorithms.py", line 15, in <module>
from pandas._typing import AnyArrayLike, ArrayLike, DtypeObj, FrameOrSeriesUnion
ImportError: cannot import name 'FrameOrSeriesUnion' from 'pandas._typing' (C:\Users\Lenovo\anaconda3\envs\pythonProject\lib\site-packages\pandas\_typing.py)
Process finished with exit code 1
解决方案
我解决了这个错误。Pandas 需要 NumPy、python-dateutil 和 pytz。我没有安装 dateutil 和 pytz。所以我安装了 dateutil 和 pytz。
推荐阅读
- ios - 删除特定部分中的 UITableView 单元格
- pandas - matplotlib 绘制多级数据框
- google-cloud-platform - Google Cloud Genomics Pipeline 区域和区域规范错误
- php - Laravel Eloquent 忽略多态关系中的 mutator
- python - 如何在 Python 中将浮点记数法转换为 10 次科学记数法的幂?
- php - PHP Post 为空然后分配默认值
- xamarin - Xamarin.Android 在左右角添加工具栏项
- android - SQLite 中的表中的表
- angular - 多次调用Angular Service单例构造函数
- amazon-web-services - 如果其中一个命令失败,则在构建阶段执行剩余命令