Fallenour
Fallenour

Reputation: 72

Not receiving output from Pandas from data.head(), but am receiving it from print of the same file

Im trying to get better with Pandas, and start integrating a bunch of jobs into a json format so I can upload it into a jobboard Im working on for a bunch of people who have been laid off, but I dont understand this issue, it doesnt make any sense. Im following what appears to be exceptionally basic guides, using Visual Studio Code at the moment, and its returning the information as expected when I run the code from print(), but not from data.head().

The Tutorials:

https://www.geeksforgeeks.org/python-pandas-dataframe-insert/

https://gokhanatil.com/2017/10/python-for-data-science-importing-csv-json-excel-using-pandas.html

Am I missing a module or something? I have Pandas installed, and it doesnt list additional modules required in either instance.

import pandas as pd   

# reading csv file 
data_CSV = pd.read_csv('test2.csv') 

# displying  dataframe - Output 1 
data_CSV.head()

print("============================================================================")

print(data_CSV)

# inserting column with static value in data frame 
#data_CSV.insert(2, "Team", "Any") 

# displaying data frame again - Output 2 
#data_CSV.head() 

Code Output:

============================================================================
      pokemon   type
0   Bulbasaur  Grass
1     Ivysaur  Grass
2    Venusaur  Grass
3  Charmander   Fire
4  Charmeleon   Fire
5   Charizard   Fire

Upvotes: 0

Views: 769

Answers (1)

John Sloper
John Sloper

Reputation: 1821

data_CSV.head() does not print anything. Rather it returns the head of the table (5 rows by default? unsure).

Change it to print(data_CSV.head()) if you want to see the output.

Upvotes: 1

Related Questions