0

I am using pandas to work with an excel file and create a dataframe from that. It's able to read the file, but when i print the resulting dataframe it's showing up in a text format which is a lot different from the normal one we are used to.

This is how i'm reading the excel file and printing it:

locations = pd.read_excel('file.xlsx') 
print(locations)

this outputs as bad dataframe which looks like a text output

I want it to output normally like this:

good dataframe

how can i fix my output?

S Ali
  • 35
  • 4
  • 2
    You likely need to pass some additional parameters to `pd.read_excel()`. See the [API page](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_excel.html). – Brendan Jul 17 '19 at 18:18
  • 1
    I think you may find this to be helpful: https://stackoverflow.com/questions/18528533/pretty-printing-a-pandas-dataframe – Kunal Narang Jul 17 '19 at 18:25

2 Answers2

1

The 'pretty'format is only outputted when 'print' isn't called. Try:

locations = pd.read_excel('file.xlsx')
locations
Eduardo Trunci
  • 165
  • 1
  • 8
1

In a Jupyter notebook (which I believe you are using):

  • Calling print(dataframe) will print results just like a python console will display, in this case like the text example you showed
  • Calling dataframe and running a cell will print the dataframe in the prettyfied format you show in your second example

As long as you have a DataFrame, the format you see when printing it will not depend on the contents of the DataFrame, just how you actually print it

NickHilton
  • 662
  • 6
  • 13