Python Forum
Pandas dataframe columns collapsed in Spyder when printing
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!
Reply
#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.
Reply
#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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  update values in one dataframe based on another dataframe - Pandas iliasb 2 669 Aug-14-2021, 12:38 PM
Last Post: jefsummers
  empty row in pandas dataframe rwahdan 3 606 Jun-22-2021, 07:57 PM
Last Post: snippsat
  Convert several columns to int in dataframe Krayna 2 497 May-21-2021, 08:55 AM
Last Post: Krayna
  iretate over columns in df and calculate euclidean distance with one column in pandas Pit292 0 768 May-09-2021, 06:46 PM
Last Post: Pit292
  pandas.to_datetime: Combine data from 2 columns ju21878436312 1 836 Feb-20-2021, 08:25 PM
Last Post: perfringo
  Remove extra count columns created by pandas groupby spyf8 1 904 Feb-10-2021, 09:19 AM
Last Post: Naheed
  Outputs "NaN" after "DataFrame columns" function? epsilon 7 1,069 Jan-27-2021, 10:59 AM
Last Post: epsilon
Question Pandas - Creating additional column in dataframe from another column Azureaus 2 921 Jan-11-2021, 09:53 PM
Last Post: Azureaus
  Comparing results within a list and appending to pandas dataframe Aryagm 1 738 Dec-17-2020, 01:08 PM
Last Post: palladium
  How to search for specific string in Pandas dataframe Coding_Jam 1 985 Nov-02-2020, 09:35 AM
Last Post: PsyPy

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020