Alan
Alan

Reputation: 559

Replicating Microsoft Excel's Data Bar Gradient Conditional Formatting Using Python / Pandas

Is there a Python package or library which allows data to be visualised in a similar way to the data bar (gradient fill) conditional formatting of Microsoft Excel:

gradient fill

If not gradient fill, the perhaps solid fill like this:

solid fill

I'm wondering whether Pandas or another Python library has this functionality?

Upvotes: 1

Views: 409

Answers (1)

wwnde
wwnde

Reputation: 26676

Some sample data would have been handy.

Generate data :

data ={'MM-DD':['Jan-01-2019', 'Feb-02-2019', 'Mar-03-2019', 'Apr-04-2019', 'May-05-2019', 'Jun-06-2019','Jul-07-2019', 'Aug-08-2019', 'Sep-09-2019', 'Oct-10-2019', 'Nov-11-2019', 'Dec-12-2019'], 'clients':[12, 34, 67, 2, 12, 17,2, 5, 43, 32, 2, 7]}
df=pd.DataFrame.from_dict(data)
df



 df.set_index(df['MM-DD'], inplace=True)
 df['Dates']=df.index.strftime('%b-%d')

Plot in matplotlib library

import matplotlib .pyplot as plt
plt.barh( df['Dates'],df['clients'])
plt.ylabel('Dates')
plt.title('2018')
plt.show

enter image description here

Can also use seaborn library

import seaborn as sns
ax = sns.barplot(x=df['clients'], y=df['Dates'])
plt.title("2018")

enter image description here

Upvotes: 1

Related Questions