本课将继续学习其他类型的统计图,有了上一课的基础,学习下面的内容就比较容易了。不同类型的统计图,只是生成 Trace 对象的类的名称变化一下,其参数的调用方式大同小异。因此,当本课介绍几种统计图时,可能就不如以往那么细致,如果读者想要详细了解某些细节,就需要亲自阅读文档——这种方法是必须要掌握的。
4.3.1 饼图
继续使用上一课的数据集。
import pandas as pd
import plotly as py
import plotly.graph_objs as go
py.offline.init_notebook_mode(connected=True)
df = pd.read_csv("/Users/qiwsir/Documents/Codes/DataSet/universityrank/timesData.csv")
用饼图统计入榜的中国大学 Top5。
dfcn = df[df['country']=='China']
dfcn5 = dfcn.iloc[:5, :]
dfcn5
world_rank | university_name | country | teaching | international | research | citations | income | total_score | num_students | student_staff_ratio | international_students | female_male_ratio | year | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
36 | <