擅长:python、mysql、java
<p>您可以将熊猫与seaborn结合使用,以简化此过程:</p>
<pre><code>import pandas as pd
import seaborn as sns
df = sns.load_dataset("tips")
x, y, hue = "day", "proportion", "sex"
hue_order = ["Male", "Female"]
(df[x]
.groupby(df[hue])
.value_counts(normalize=True)
.rename(y)
.reset_index()
.pipe((sns.barplot, "data"), x=x, y=y, hue=hue))
</code></pre>
<p><a href="https://i.stack.imgur.com/Oz50h.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Oz50h.png" alt="enter image description here"/></a></p>