gpt4 book ai didi

python - 使用 "Pandas"和 "Seaborn"在 PyCharm 中键入错误

转载 作者:行者123 更新时间:2023-12-05 05:50:01 24 4
gpt4 key购买 nike

我目前正在使用带有 IDE PyCharm 的 Python 来绘制在带有 seaborn 的 pandas 中生成的数据框。我正在应用以下代码:

from matplotlib import pyplot as plt
import pandas as pd
import seaborn as sns

netflix_stocks = pd.read_csv("NFLX.csv")
dowjones_stocks = pd.read_csv("DJI.csv")
netflix_stocks_quarterly = pd.read_csv("NFLX_daily_by_quarter.csv")

# rename columns
netflix_stocks.rename(columns = {'Adj Close': 'Price'}, inplace = True)
dowjones_stocks.rename(columns = {'Adj Close': 'Price'}, inplace = True)
netflix_stocks_quarterly.rename(columns = {'Adj Close': 'Price'}, inplace = True)


# visualizing the netflix quarterly data
ax = plt.subplot()
sns.violinplot(data = netflix_stocks_quarterly, x = "Quarter", y = "Price")
ax.set_title("Distribution of 2017 Netflix Stock Prices by Quarter")
plt.xlabel("Business Quarters in 2017")
plt.ylabel("Closing Stock Price")

plt.savefig("Distribution of 2017 Netflix Stock Prices by Quarter.png")
plt.show()

这导致我看到错误消息

Traceback (most recent call last):
File "D:\testproject\venv\lib\site-packages\numpy\core\getlimits.py", line 459, in __new__
dtype = numeric.dtype(dtype)
TypeError: 'NoneType' object is not callable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\Program Files (x86)\PyCharm Community Edition 2021.3.1\plugins\python-ce\helpers\pydev\pydevd.py", line 1483, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
File "D:\Program Files (x86)\PyCharm Community Edition 2021.3.1\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "D:/testproject/main.py", line 18, in <module>
sns.violinplot(data = netflix_stocks_quarterly, x = "Quarter", y = "Price")
File "D:\testproject\venv\lib\site-packages\seaborn\_decorators.py", line 46, in inner_f
return f(**kwargs)
File "D:\testproject\venv\lib\site-packages\seaborn\categorical.py", line 2408, in violinplot
plotter.plot(ax)
File "D:\testproject\venv\lib\site-packages\seaborn\categorical.py", line 1043, in plot
self.draw_violins(ax)
File "D:\testproject\venv\lib\site-packages\seaborn\categorical.py", line 801, in draw_violins
self.draw_box_lines(ax, violin_data, support, density, i)
File "D:\testproject\venv\lib\site-packages\seaborn\categorical.py", line 967, in draw_box_lines
ax.scatter(center, q50,
File "D:\testproject\venv\lib\site-packages\matplotlib\__init__.py", line 1412, in inner
return func(ax, *map(sanitize_sequence, args), **kwargs)
File "D:\testproject\venv\lib\site-packages\matplotlib\axes\_axes.py", line 4487, in scatter
self.add_collection(collection)
File "D:\testproject\venv\lib\site-packages\matplotlib\axes\_base.py", line 2242, in add_collection
self._unstale_viewLim()
File "D:\testproject\venv\lib\site-packages\matplotlib\axes\_base.py", line 776, in _unstale_viewLim
self.autoscale_view(**{f"scale{name}": scale
File "D:\testproject\venv\lib\site-packages\matplotlib\axes\_base.py", line 2932, in autoscale_view
handle_single_axis(
File "D:\testproject\venv\lib\site-packages\matplotlib\axes\_base.py", line 2895, in handle_single_axis
x0, x1 = locator.nonsingular(x0, x1)
File "D:\testproject\venv\lib\site-packages\matplotlib\ticker.py", line 1654, in nonsingular
return mtransforms.nonsingular(v0, v1, expander=.05)
File "D:\testproject\venv\lib\site-packages\matplotlib\transforms.py", line 2880, in nonsingular
if maxabsvalue < (1e6 / tiny) * np.finfo(float).tiny:
File "D:\testproject\venv\lib\site-packages\numpy\core\getlimits.py", line 462, in __new__
dtype = numeric.dtype(type(dtype))
TypeError: 'NoneType' object is not callable
python-BaseException
Backend TkAgg is interactive backend. Turning interactive mode on.

出于某种原因,相同的代码在 jupyter notebook 下工作。我正在导入以下版本的 pandas、matplotlib 和 seaborn:

versions of pckages imported

此外,我使用虚拟环境创建了一个项目,如下所示:

project creation with a virtual environment

由于数据帧没有“空”条目或那些必须更改数据类型的条目,我无法找出原因。应该绘制的数据框如下所示:

dataframe

我很感激任何建议!

提前致谢,乔纳斯

最佳答案

我有一个类似的问题,我通过降级 numpy 包解决了这个问题。我使用的是 1.22.3,后来改成了 1.22.2。

pip3卸载numpy

然后

pip3 安装 numpy==1.22.2

关于python - 使用 "Pandas"和 "Seaborn"在 PyCharm 中键入错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70591652/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com