Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Pandas dataframe columns collapsed in Spyder when printing
#1
Hello everyone!

I have this tiny problem when using Pandas inside the Spyder IDE. BTW I am still kind of new to Python and libraries so I hope you can forgive me for my beginner question.

So, what I want is to print a preview of a query I made with Google BigQuery (health data). For this, I used

print(df.head(5))
in my script.

However, what I get in the console view is a "collapsed" view of the data frame with columns replaced by dots in the console, like this:

Per stat:
  provider_city  ... average_medicare_payments
0      ABINGTON  ...                   3992.93
1         AKRON  ...                   4292.47
2        ALBANY  ...                   3834.18
3        ALBANY  ...                   5137.31
4     ALLENTOWN  ...                   3913.78
Note the dots replacing the columns. I have seen other examples of this, and in that case the columns were shown in the preview. So is there a way to enable a wider view of the data frame? I have searched on the internet but all the solutions I tried didn't work as intended Huh

What I did in my case was to use tkinter to print the entire sheet instead and look at the data. But since this is kind of irritating doing all the time when working with my data, I would love to hear your opinion on this matter.

Thanks very much in advance!
Quote
#2
This may or may not work for you.
pd.set_option("display.max_columns",200)
it will display up to 200 columns. However, it will do so by displaying them in groups, stacked on each other.
Quote
#3
(Nov-02-2019, 06:33 PM)jefsummers Wrote: This may or may not work for you.
pd.set_option("display.max_columns",200)
it will display up to 200 columns. However, it will do so by displaying them in groups, stacked on each other.

Thank you so much, this did the trick! This method surely will be most useful for me in my tasks Cool

Thank you for your assistance Big Grin

EDIT: I noticed that in some cases this method doesn't quite work as intended (like you implied) Tongue I was lucky with my first attempt and in that case my dataframe was presented nicely. However, my other dataframes look kind of messy with this setting. So I guess you are right, it is not a "general solution". But is surely is helpful to know about this method as it may actually be the right solution in some cases Tongue

For this project, I guess I will just stick with tkinter and view the full sheet Shy
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  How does pyplot know what was plotted by the output of pandas.DataFrame(...).cumprod( codeowl 2 109 Mar-28-2020, 08:27 AM
Last Post: j.crater
  DataFrame: To print a column value which is not null out of 5 columns mani 2 144 Mar-18-2020, 06:07 AM
Last Post: mani
  Ordering of pandas DataFrame new_to_python 5 190 Mar-15-2020, 06:08 PM
Last Post: new_to_python
Question Dividing a single column of dataframe into multiple columns based on char length darpInd 2 166 Mar-14-2020, 09:19 AM
Last Post: scidam
  Pandas dataframe merge snmmat 1 165 Mar-09-2020, 06:56 PM
Last Post: jefsummers
  Interate for loop over certain columns in dataframe Finpyth 2 147 Mar-06-2020, 08:34 AM
Last Post: Finpyth
  Transform Facebook Graph API insights JSON to pandas dataframe usman 0 182 Mar-03-2020, 05:14 AM
Last Post: usman
  How to highlight dataframe columns SriRajesh 1 162 Feb-28-2020, 11:02 PM
Last Post: Marbelous
  Obtaining Correct Date In Pandas DataFrame eddywinch82 14 1,230 Feb-17-2020, 11:45 AM
Last Post: eddywinch82
  Does the order of columns in the DataFrame matter? new_to_python 11 373 Feb-17-2020, 12:32 AM
Last Post: scidam

Forum Jump:


Users browsing this thread: 1 Guest(s)