Pandas Python + Format For Values
This is the code: import pandas as pd from pandas import Series, DataFrame import numpy as np import matplotlib.pyplot as plt df.head(3).style.format({'Budget': '€ {:
Solution 1:
I advise you not to mix logic with appearance. Create the table according to logic, and then format it. Try this code:
datos1= df.loc[ \
df.Participation. \
str.contains('Coordinator',case=False) \
& df.Country. \
str.contains('Greece',case=False) ]
datos1_pretty= datos1.style.format({"Budget":'€ {0:,.0f}'})
You can specify more columns in the dict.
Solution 2:
datos1.Budget.sum()
is the sum of a series, which returns a float
, so you can't apply Pandas style.format
to it. Try this:
'€ {0:,.0f}'.format(datos1.Budget.sum())
For the table: df['Budget'] = df.Budget.apply('€ {0:,.0f}'.format)
, if you want to have formatted strings in the Budget
column. style.format
only works when you have an html frontend, i.e. jupyter.
Post a Comment for "Pandas Python + Format For Values"