Pandas Dataframe column width setting does not work - pandas

I used these settings to display the entire dataframe
pd.set_option('display.max_rows', None)
pd.set_option('display.max_columns', None)
pd.set_option('display.width', None)
pd.set_option('display.max_colwidth', None)
However, the columns with text are displayed in a very narrow mode, around 20 characters. The complete text is displayed, no truncation. I formerly used pd.set_option('display.max_colwidth', -1)or set a character limit e.g. pd.set_option('display.max_colwidth', 450) which worked fine and adjusted the column width accordingly. Any ideas what went wrong this time?
Help is very much appreciated because the results I get are VERY long and narrow columns :(

Related

display output pandas dataframe in rstudio

One question please.
I like to use rstudio to code in python and R, but when I print a pandas dataframe I get output that doesn't use all the space. It is not very friendly and it is worse if I have more variables.
As shown in the attached image.
Is there a way to display the columns to the right like we do with tibble in r?
Thanks!
I have tried using these options but it doesn't work.
pd.set_option('display.max_columns', None)
pd.set_option('display.width', None)

How to fine-tune column widths of a table displayed on a tkinter frame using pandastable?

I'm placing a pandas dataframe, df, on a tkinter frame, my_frame, using the pandastable package. The dataframe has four columns and, despite looking through the pandastable documention, I'm struggling to modify the column widths so that none of the column headers are truncated. Here's my relevant code, where my dataframe, df has already been created.
from pandastable import Table, config
table = Table(my_frame,dataframe=df,width=425,height=275,showtoolbar=False)
options=config.load_options() # use config to change fontsize option
options={'fontsize':18}
config.apply_options(options,table)
# Now I try to adjust widths of four columns:
table.columnwidths={'Channel':25,'Start (sec)':75,'Stop (sec)':75,'Peak Frequency
(Hz)':250}
It seems no matter what I do, widths of the 'Start' and 'Stop' columns don't expand, which truncates their column headers as in the image below. I've tried increasing them from 75 to 80 to 85, etc., while increasing the overall width of table correspondingly, but I can't get things to work the way I want.
This seemed to work:
pt=Table(table_frame,dataframe=df,width=450,height=275)
options=config.load_options()
options={'fontsize':18,'cellwidth': 100}
config.apply_options(options,pt)
pt.columnwidths['Peak Frequency (Hz)'] = 225
pt.columnwidths['Channel'] = 25
Default font is 18, and we override just two of the columns.

Jupyter Notebook still truncating pandas columns

So, I have a pandas data frame with two fields
partition
account_list
1
[id1,id2,id3,...]
2
[id4,id6,id5,...]
since the list is quite long and I want to see the complete content I'm using
pd.set_option('display.max_rows', None)
pd.set_option('display.max_columns', None)
pd.set_option('display.width', None)
pd.set_option('display.max_colwidth', -1)
louvain_communities.limit(tot_communities).toPandas()
nevertheless, as you can see (Jupiter I think) still truncate the column (I had to edit out the data for privacy)
Is there a way to fix this? I really need to check have the complete list, not truncated, to be shown.
max_colwidth and max_seq_items together work. Code below synthesises list with 500 items. Change the range() and you can test however many you want.
import pandas as pd
pd.set_option("max_colwidth", None)
pd.set_option("max_seq_items", None)
pd.DataFrame([{"partition":i, "account_list":[f"id{j}" for j in range(500)]} for i in range(2)])

How to make pandas show the entire dataframe without cropping it by columns?

I am trying to represent cubic spline interpolation information for function f(x) as a dataframe.
When trying to print into a spyder, I find that the columns are being cut off. When trying to reproduce the output in Jupiter Lab, I got the same thing.
When I ran in ipython via terminal I got the desired full dataframe output.
I searched the integnet and tried the pandas commands setting options pd.set_options(), but nothing came of it.
I attach a screenshot with the output in ipython.
In Juputer can use:
from IPython.display import display, HTML
and instead of
print(dataframe)
use of in anyway place
display(HTML(dataframe.to_html()))
This will create a nice table.
Unfortunately, this will not work in the spyder. So you can try to adjust the width of the ipython were suggested. But in most cases this will make the output poorly or unreadable.
After trying the dataframe methods, I found what appears to be a cropping setting.
In Spyder I used:
pd.set_option('expand_frame_repr', False)
print(dataframe)
This method explains why increasing max_column didn't help me previously.
You can specify a maximum number for rows or columns using pd.set_options(display.max_columns=1000)
But you don't have to set an arbitrary value, but rather use None instead to make sure every size will be covered.
For rows, use:
pd.set_option('display.max_rows', None)
And for columns, use:
pd.set_option('display.max_columns', None)
It is a result of the display width. You can use the following set_options():
pd.set_options(display.width=1000) #make huge
You may also have to raise max columns but it should be smart enough to adjust automatically after you make width bigger:
pd.set_options(display.max_columns=None)

Pycharm injects new line in output, half way through dataset columns

Why would Pycharm put the second half of my dataset on a new line? (see Image) How do I turn this off?
I would like to display my dataset as wide as possible, with no wrapping.
The console attempts to auto-detect the width of the display area, but when that fails it defaults to 80 characters. This behavior can be overridden with:
import pandas as pd
pd.set_option('display.width', 400)
pd.set_option('display.max_columns', 10)
please take reference from this stackoverflow
Getting wider output in PyCharm's built-in console