38 lines
993 B
Python
38 lines
993 B
Python
import plotly.express as px
|
||
import pandas
|
||
df = px.data.gapminder()
|
||
df1 = df.query("country == 'United States' or continent == 'Asia'")
|
||
|
||
|
||
# 根据大陆对数据进行分组,并计算每个大陆的人均GDP平均值
|
||
gdpPercap_summary = df.groupby('continent')[['gdpPercap','lifeExp']].mean().reset_index()
|
||
|
||
# 显示结果
|
||
print(gdpPercap_summary)
|
||
|
||
print(df1.columns)
|
||
fig = px.line(df1,
|
||
x="year",
|
||
y="lifeExp",
|
||
# color="continent",
|
||
title="A Plotly Express Figure",
|
||
markers=True,
|
||
# symbol="continent",
|
||
line_shape="linear"
|
||
)
|
||
# ['linear', 'hv', 'vh', 'hvh', 'vhv']
|
||
df2 = df.query("continent == 'Oceania'")
|
||
fig = px.bar(df2,
|
||
x="year",
|
||
y="pop",
|
||
color="country",
|
||
barmode="group"
|
||
)
|
||
df = px.data.tips()
|
||
print(df.columns)
|
||
fig = px.pie(df,values="total_bill",names="day"
|
||
)
|
||
|
||
fig.show()
|
||
|