简体   繁体   中英

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.

I have a very simple code, that I can execute well in Jupyter, but it does not work in 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. 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

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. Code worked flawlessly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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