当我运行这段代码

import pandas as pd
import numpy as np
def add_prop(group):
    births = group.births.astype(float)
    group['prop'] = births/births.sum()
    return group

pieces = []
columns = ['name', 'sex', 'births']

for year in range(1880, 2012):
    path = 'yob%d.txt' % year
    frame = pd.read_csv(path, names = columns)
    frame['year'] = year
    pieces.append(frame)
    names = pd.concat(pieces, ignore_index = True)

total_births = names.pivot_table('births', rows = 'year', cols = 'sex', aggfunc = sum)
total_births.plot(title = 'Total Births by sex and year')

我没有情节。这来自Wes McKinney的书,该书使用Python进行数据分析。
谁能指出我正确的方向?

最佳答案


import matplotlib.pyplot as plt

在顶部,和
plt.show()

在最后。

10-06 05:55