import pandas as pd
df2 = pd.DataFrame.from_records(
{'Compared': {0: -0.090909090999999997,
1: -0.130434783,
2: -0.10714285699999999,
3: -0.15966386599999999},
'LastYR': {0: 5500.0, 1: 115.0, 2: 84.0, 3: 40520.523399999998},
'METRIC': {0: 'Visits', 1: 'Units', 2: 'Orders', 3: 'Sales'},
'Today': {0: 5000.0, 1: 100.0, 2: 75.0, 3: 34050.860000000001},
'region_rollup': {0: 'America', 1: 'America', 2: 'America', 3: 'America'}}
)
df2.head()
How can I apply:
a) a % format to any entire column I would like
b) A currency $ format to any row where the METRIC value is 'Sales'
I have tried the df.style.format() function, which will let me subset columns and apply the % formatting, but I cannot determine what kind of function to write which would allow me to format a column, based on the value of another column (again, "if metric = sales then format today as currency", more or less).
Thanks!
