使用Python/Pandas复制Microsoft Excel的数据栏渐变条件格式 [英] Replicating Microsoft Excel's Data Bar Gradient Conditional Formatting Using Python / Pandas
本文介绍了使用Python/Pandas复制Microsoft Excel的数据栏渐变条件格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有一个Python包或库,该包或库允许以类似于Microsoft Excel的数据栏(渐变填充)条件格式的方式显示数据:
如果不是渐变填充,则可能是如下所示的实心填充:
我想知道Pandas或其他Python库是否具有此功能?
解决方案
一些示例数据会很方便.
生成数据:
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"],客户":[12、34、67、2、12、17、2、5、43、32、2、7]}df = pd.DataFrame.from_dict(数据)dfdf.set_index(df ['MM-DD'],inplace = True)df ['Dates'] = df.index.strftime('%b-%d')
在
也可以使用
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:
If not gradient fill, the perhaps solid fill like this:
I'm wondering whether Pandas or another Python library has this functionality?
解决方案
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
Can also use seaborn library
import seaborn as sns
ax = sns.barplot(x=df['clients'], y=df['Dates'])
plt.title("2018")
这篇关于使用Python/Pandas复制Microsoft Excel的数据栏渐变条件格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文