Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 16832

How to fix issue with column alignment when printing pandas dataframe with emojis?

$
0
0

When printing a DataFrame with emojis, the column header alignment issue worsens with more columns. This doesn't happen without emojis. Any solutions?

With Emojis

import pandas as pdpd.set_option('display.max_rows',    1000)pd.set_option('display.max_columns', 1000)pd.set_option('display.width',       1000)example = {'normal_col'  : [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],'text_col'    : ['hello world'] * 10,'emoji_col_A' : ['🟩 hello world'] * 10,'emoji_col_B' : ['🟥 hello world'] * 10,'emoji_col_C' : ['🟧 hello world'] * 10,'emoji_col_D' : ['🟨 hello world'] * 10}df = pd.DataFrame(example)print(df)
   normal_col     text_col    emoji_col_A    emoji_col_B    emoji_col_C    emoji_col_D0           1  hello world  🟩 hello world  🟥 hello world  🟧 hello world  🟨 hello world1           2  hello world  🟩 hello world  🟥 hello world  🟧 hello world  🟨 hello world2           3  hello world  🟩 hello world  🟥 hello world  🟧 hello world  🟨 hello world3           4  hello world  🟩 hello world  🟥 hello world  🟧 hello world  🟨 hello world4           5  hello world  🟩 hello world  🟥 hello world  🟧 hello world  🟨 hello world5           6  hello world  🟩 hello world  🟥 hello world  🟧 hello world  🟨 hello world6           7  hello world  🟩 hello world  🟥 hello world  🟧 hello world  🟨 hello world7           8  hello world  🟩 hello world  🟥 hello world  🟧 hello world  🟨 hello world8           9  hello world  🟩 hello world  🟥 hello world  🟧 hello world  🟨 hello world9          10  hello world  🟩 hello world  🟥 hello world  🟧 hello world  🟨 hello world

Without Emojis

import pandas as pdpd.set_option('display.max_rows',    1000)pd.set_option('display.max_columns', 1000)pd.set_option('display.width',       1000)example = {'normal_col'  : [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],'text_col'    : ['hello world'] * 10,'emoji_col_A' : ['hello world'] * 10,'emoji_col_B' : ['hello world'] * 10,'emoji_col_C' : ['hello world'] * 10,'emoji_col_D' : ['hello world'] * 10}df = pd.DataFrame(example)print(df)
   normal_col     text_col  emoji_col_A  emoji_col_B  emoji_col_C  emoji_col_D0           1  hello world  hello world  hello world  hello world  hello world1           2  hello world  hello world  hello world  hello world  hello world2           3  hello world  hello world  hello world  hello world  hello world3           4  hello world  hello world  hello world  hello world  hello world4           5  hello world  hello world  hello world  hello world  hello world5           6  hello world  hello world  hello world  hello world  hello world6           7  hello world  hello world  hello world  hello world  hello world7           8  hello world  hello world  hello world  hello world  hello world8           9  hello world  hello world  hello world  hello world  hello world9          10  hello world  hello world  hello world  hello world  hello world

Viewing all articles
Browse latest Browse all 16832

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>