简体   繁体   English

代码在 Jupyter 中有效但在 PyCharm 中无效

[英]Code works in Jupyter but not in PyCharm

I know this might be a very simple problem to solve, but I have been googling all day and cannot make it work.我知道这可能是一个很容易解决的问题,但我整天都在谷歌上搜索,无法让它发挥作用。 Please be patient with me - I just started working with Python.请耐心等待 - 我刚刚开始使用 Python。

I have a very simple code, that I can execute well in Jupyter, but it does not work in PyCharm:我有一个非常简单的代码,我可以在 Jupyter 中很好地执行,但它在 PyCharm 中不起作用:

import matplotlib.pyplot as plt
import seaborn as sns; sns.set()
import pandas as pd
import numpy

y = pd.read_csv('data_all.csv')

df = y.iloc[:, 0:10]

print(df)

g = sns.PairGrid(df, hue='TP_PSP')
g = g.map(plt.scatter)
g = g.map_diag(plt.hist)
g = g.map_offdiag(plt.scatter)
g = g.add_legend()

I receive the following error:我收到以下错误:

Traceback (most recent call last):
  File "C:/Users/lukas/PycharmProjects/untitled/mtth-matplot.py", line 18, in <module>
    g = g.map_diag(plt.hist)
  File "C:\Users\lukas\PycharmProjects\untitled\venv\lib\site-packages\seaborn\axisgrid.py", line 1399, in map_diag
    func(data_k, label=label_k, color=color, **kwargs)
  File "C:\Users\lukas\PycharmProjects\untitled\venv\lib\site-packages\matplotlib\pyplot.py", line 3132, in hist
    stacked=stacked, normed=normed, data=data, **kwargs)
  File "C:\Users\lukas\PycharmProjects\untitled\venv\lib\site-packages\matplotlib\__init__.py", line 1855, in inner
    return func(ax, *args, **kwargs)
  File "C:\Users\lukas\PycharmProjects\untitled\venv\lib\site-packages\matplotlib\axes\_axes.py", line 6713, in hist
    labels = [six.text_type(lab) for lab in label]
TypeError: 'numpy.int64' object is not iterable

I have all packages installed and the interpreter works for "normal" python code.我已经安装了所有软件包,并且解释器适用于“普通”python 代码。 I am sorry posting such a trivial problem, but I cannot find a solution on the web that works for me.很抱歉发布这样一个微不足道的问题,但我无法在网络上找到适合我的解决方案。 I am so grateful every hint to make it work.我非常感谢每一个让它发挥作用的提示。

Thanks in advance and best regards提前致谢并致以最诚挚的问候

LGR LGR

This worked.这奏效了。 I was facing a similar problem.我面临着类似的问题。 Changed the Python Interpreter from 2.7 to 3.8 by clicking in the lower left portion of the Pycharm screen where it shows the interpreter being used.通过单击显示正在使用的解释器的 Pycharm 屏幕的左下部分,将 Python 解释器从 2.7 更改为 3.8。 Code worked flawlessly.代码完美无缺。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM