python - Text formatting on pandas pivot table -
i creating dataframe , converting dataframe pivot table. text , column headers in pivot table aligned center in result. set text justify "left". please ? i've tried df.to_string(justify = 'true')
throws attribute error "'unicode' object has no attribute 'columns'"
this dataframe:
df = dataframe({'customer': customercol,'title': titlecol,'count':countcol}) table = pivot_table(df,index = ['customer','title'],values='count')
i think need set parameter justify
left
in to_string
:
import pandas pd df = pd.dataframe({'customer': ['ann green', 'joseph smith', 'ann green'], 'title': ['ms', 'mr', 'ms'], 'count':[4, 6, 7]}) print (df) customer title count 0 ann green ms 4 1 joseph smith mr 6 2 ann green ms 7 table = pd.pivot_table(df,index = ['customer','title'],values='count').reset_index() print (table) customer title count 0 ann green ms 5.5 1 joseph smith mr 6.0 print (table.to_string(justify = 'left')) customer title count 0 ann green ms 5.5 1 joseph smith mr 6.0
Comments
Post a Comment