Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyCharm: How to display all columns of dataframe in 'run' window without wrapping or truncation?

The issue I am facing has to do with how I can force the 'Run' window to show all columns of a given pandas dataframe, without fitting it to the size of the window (which happens for me either by truncation of column names, or by not showing all columns).

In other words I need the data to be shown on their intended rows and, if the window view is too small to show all the columns, a horizontal bar should appear (like normally) to allow me to easily traverse the data.

Background: I have processed some data, where I automatically select and store different parts of the data in specific ".h5" files, in table format. This is done using pandas dataframes and the 'to_hdf' function. Then I read it in and get the following: view in the 'Run' output window

The dataset consists of 35 columns (excluding Time column), with x amount of entries in each of them. For this post, they have been named arbitrarily, to illustrate the issue.

Note that:

  • Soft-wrap is disabled in File -> Settings -> Editor -> General under 'Soft Wraps'
  • I just performed a fresh install of both Python 3.7 and PyCharm Community Edition 2018.3.5 (had some issue with 2019.1 version initially), with some imported PyCharm settings from the export file from PyCharm in my computer back home
  • Horizontal scrollbar seems disabled. Does not appear at any point. Which is weird, seeing as my computer back home gives me the horizontal scroll bar
  • Since the output in the 'Run' window wraps and truncates according to the size of the window prior to running the script (ie. smaller vs full screen window), the horizontal scrollbar most likely will re-activate once the other effects are removed

I want to accomplish three things:

  1. Show all columns of dataframe while allowing me to scroll through these with a horizontal scroll bar (seems disabled at the moment), which implies:
  2. No wrapping of column names, see mark (1) and (2) from above image. And no truncation / removal of columns due to size limit of 'Run' window, see mark (3) from the same image.
  3. Minor task: Currently, the 'Time' column (which is set as row index) prints as only date in this printout, while also hours, minutes and seconds are stored. Hopefully this is automatically fixed once 1. and 2. are fixed (my other tables show full date + hours, etc without problem).

This is what I have tried

I have used the following two lines to improve the printout somewhat:

pd.set_option('display.max_columns', 20)
pd.set_option('display.width', 2000)

This gives a neat output, see below: this

However, not all of the 35 columns are shown, see mark (1) / the ". . ." marks. When I increase the allowed column count from 20 to 40, pd.set_option('display.max_columns', 40), this happens: happens

It seems we are back to square one. Luckily, one of the negative effects are gone, namely the truncation effect, ie. what I think of as the removal of the shown columns.

The wrapping of the columns still occurs, though, such that there are now double the amount of rows while it should be possible to show everything on their own rows while automatically showing a horizontal bar to let the user traverse this data.

I have also looked at this link to understand more of the options with the set_option methods of pandas. I found and tried this line, pd.set_option('expand_frame_repr', True), in addition to the other lines I've used. But it did not change anything in my case.

Any ideas?

like image 856
Fhyarnir Avatar asked Apr 06 '19 00:04

Fhyarnir


People also ask

What is a column in PyCharm?

Professional feature: download PyCharm Professional to try. A column is a piece of data that is stored by a table. This data belongs to a particular type. A column may include text, numbers, or pointers to files in the operating system.

How to display all rows of Dataframe in pandas?

Setting to display All rows of Dataframe In pandas when we print a dataframe, it displays at max_rows number of rows. If we have more rows, then it truncates the rows. pandas.options.display.max_rows This option outlines the maximum number of rows that pandas will present while printing a dataframe. The default value of max_rows is 10.

How do I view coordinates in PyCharm?

Currently, PyCharm supports coordinates in the following formats: WKT, WKB, and PostGIS geometry 4326. In the Database tool window ( View | Tool Windows | Database ), double-click the table with geographical data. Click the Show Options Menu icon () and select Show Geo Viewer.

How to show all columns of a pandas data frame in Jupyter?

In this article, we will discuss how to show all the columns of a pandas data frame in jupyter notebook. Pandas have a very handy method called get option (), by this method, we can customize the output screen and work without any inconvenient form of outputs. set_option () used to set the value.


3 Answers

let's say you want to print X which has 15 rows.

A simple command that worked for me is:

print(X.to_string())

like image 83
Charles Avatar answered Jan 02 '23 17:01

Charles


So after much research I found 2 ways to get my column heads in my data base that has for this job so far, (2152 rows, 119 columns).

First way which is, meh, to to call them to a list which go all the way horizontal like. My DataFrame = df

print(df.columns.tolist())

Second way was to display not only the entire data base in pycharms or where ever. It will take out the truncates entirely, but i had to use two type of max rows columns aspects which is weird. No other way, by it self worked for me.

pd.options.display.width= None
pd.options.display.max_columns= None
pd.set_option('display.max_rows', 3000)
pd.set_option('display.max_columns', 3000)

Then just print your dataframe 
print(df)

With those 4 lines of code, I can open any data base less than 3000 cols/rows and see everything. Pretty happy about it but a little confused why no one, pd.options or pd.set_option, wouldn't work by themselves.

Any who happy coding.

like image 24
JQTs Avatar answered Jan 02 '23 16:01

JQTs


I create a final variable at the end of my program, say something like .... end = 'end'

Then I put a debug break point there, and run the program in debug mode. It will stop at the end and you can open the dataframe up in debug mode, and la voila... you can move around the whole dataframe with color coding no less and other options available in debug mode.

like image 21
run-out Avatar answered Jan 02 '23 17:01

run-out