Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the pandas dataframe data left/right alignment?

Tags:

python

pandas

I use pd.set_option("display.colheader_justify","right") to set the column header. But I can't find the option for data by pd.describe_option().

How to set the data within a dataframe display left or right alignment for each column? Or, is it possible to define a format template for the whole row data display?

like image 708
bigbug Avatar asked Jun 21 '13 09:06

bigbug


People also ask

How do I change the alignment of a Dataframe in Python?

In order to align columns to left in pandas dataframe, we use the dataframe. style. set_properties() function.

What is data alignment in pandas?

3 minute read. Pandas Align basically helps to align the two dataframes have the same row and/or column configuration and as per their documentation it Align two objects on their axes with the specified join method for each axis Index.

How do I rearrange data in pandas?

In order to sort the data frame in pandas, function sort_values() is used. Pandas sort_values() can sort the data frame in Ascending or Descending order.


1 Answers

If you want to change the display in a Jupyter Notebook, you can use the Style feature.

# Test data df = DataFrame({'text': ['foo', 'bar'],                  'number': [1, 2]})  df.style.set_properties(**{'text-align': 'right'}) 

enter image description here

like image 88
Romain Avatar answered Sep 25 '22 00:09

Romain