我目前正在使用 Python 和 IDE PyCharm 来绘制在 pandas 和 seaborn 中生成的数据框。我正在应用以下代码:
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:
导入的包的版本 https://i.stack.imgur.com/vrIxk.png
此外,我使用虚拟环境创建了一个项目,如下所示:
使用虚拟环境创建项目 https://i.stack.imgur.com/aImBn.png
由于数据帧没有“空”条目或必须更改数据类型的条目,我无法弄清楚原因。应绘制的数据框如下所示:
数据框 https://i.stack.imgur.com/eGqGN.png
我很感激任何建议!
提前致谢,
乔纳斯