Dataframe head not shown in PyCharm

15,537

Solution 1

PyCharm is not Python Shell which automatically prints all results.

In PyCharm you have to use print() to display anything.

print(df.head(10))

The same is when you run script in other IDE or editor or directly python script.py

Solution 2

For printing all data

print(df)

By Default it will print top 5 records for head.

print(df.head())

If you need 10 rows then you can write this way

print(df.head(10))

Share:
15,537

Related videos on Youtube

user1774127
Author by

user1774127

Updated on March 26, 2022

Comments

  • user1774127
    user1774127 over 2 years

    I have the following code in PyCharm

    import pandas as pd
    
    import numpy as np
    
    import matplotlib as plt
    
    df = pd.read_csv("c:/temp/datafile.txt", sep='\t')
    
    df.head(10)
    

    I get the following output:

    Process finished with exit code 0
    

    I am supposed to get the first ten rows of my datafile, but these do not appear in PyCharm.

    I checked the Project interpreter and all settings seem to be alright there. The right packages are installed (numpy, pandas, matplotlib) under the right Python version.

    What am I doing wrong? Thanks.

  • Admin
    Admin over 7 years
    Thanks so much! :-)
  • Bitcoin Cash - ADA enthusiast
    Bitcoin Cash - ADA enthusiast about 7 years
    @furas why is it that with some methods you don't need to use print then? For instance, df.info() displays the info just fine without needing any "print", whereas df.head() requires the print() wrapping it.
  • furas
    furas about 7 years
    @Tiago df.info() displays without print() because author of this method used print() inside this method. He decided that this method will be used only to display information. df.head() needs print() because it returns DataFrame which you can use in calculations before you display - i.e. df2 = df.head() * 4 or df2 = df.head()[-3]