PyCharm shows no output from pandas

2019-07-09 11:41发布

问题:

Please go easy on me, its my first days trying to use python and I already have problem with setting up enviroment.

When I use IDLE with code:

import pandas as pd

column_names = ["a,b"]
dataset = pd.read_csv('abdataset', names = column_names, index_col = False)


dataset

shows the whole dataset in quite good way.

Whenever when I try same code on PyCharm and go RUN on the console I can only see

Process finished with exit code 0

Is there any way to configure run console to show output like IDLE do?

回答1:

It sounds like you want pycharm to run an interactive console akin to idle/ipython etc.

Go to View -> Tool Windows -> Python Console and you should get a familiar interactive interpreter that you can use.

When you write and run scripts, you don't get the output akin to what you are looking for.



回答2:

In Pycharm, if you want to see something displayed in the console you need to explicitly output it. In this case, it should work if you end your code with print(dataset) to print it to the console.



回答3:

It is really not PyCharm specific behavior.

Python is an interpreted language, i. e. it executes every command immediately as you write it and confirm it with the Enter key. One command after the other.

But - as in other interpreted languages - you have another option: Write in advance all your commands into a text file and then ask Python to perform them as a batch - again one command after the other, but very fast.

In the first case - execution immediately after pressing the Enter key, it is comfortable to find of the value of a variable (or of an expression) by simply writing them - and Python display it in the standard (sometimes ugly) form. It is performed in the Python console environment, available in PyCharm IDE, too (e. g. from menu View | Tool Windows | Python console).

In the second case (the batch processing of commands) it would be not so comfortable, as commands are executed in a very fast sequence and you are generally not able to tell which output value corresponds to which variable, moreover if you often don't see your commands on your monitor. So in this case (launching a .py or .pyc file) this approach is not used and you have print them explicitely with the print command (Python 2) or print() function (Python 3). In PyCharm IDE you perform this action as you did: By running the appropriate Python file from your project.

So you have 2 possibilities in PyCharm:

  1. Use Python Console for writing all your commands, one after the other - with or without the use of the print command / print() function.
  2. Run a Python file (as you did) but with explicitly printing what you wanted to be displayed.

Note:

In the IDLE you have the same 2 possibilities with the same behavior:

  • 1st immediately after starting the IDLE,
  • 2nd after opening / creating a Python file and launching it by F5 key.


回答4:

Fixed: PyCharm shows no Error No output from pandas

Create small csv file with export>> save as Unicode UTF-8 (in Mac)

df = pd.read_csv("tstPandas.csv")

read your file and hold "df". To see output you need to print(df)

Which outputs the file