【发布时间】:2022-01-12 18:39:52
【问题描述】:
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
Female = df[(df["Gender"] == "Female")]
Male = df[(df["Gender"] == "Male")]
AgeClass = ['100+','95-99','90-94','85-89','80-84','75-79','70-74','65-69','60-64','55-59','50-54','45-49','40-44','35-39','30-34','25-29','20-24','15-19','10-14','5-9','0-4']
bar_plot = sns.barplot(x= Male, y=df['Age'], order=AgeClass)
bar_plot = sns.barplot(x= Female, y=df['Age'], order=AgeClass)
bar_plot.set(xlabel="Population (hundreds of millions)", ylabel="Age-Group", title = "Population Pyramid")
我正在尝试使用 seaborn 从 pandas df 构建人口金字塔。
我得到了值错误。帮我解决它
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
【问题讨论】: