Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Data Science by (17.6k points)

When I run this code

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


    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')

I get no plot. This is from Wes McKinney's book on using Python for data analysis. Can anyone point me in the right direction?

1 Answer

0 votes
by (41.4k points)

At the top, put this:

import matplotlib.pyplot as plt

And at the end:

Related questions

0 votes
1 answer
asked Oct 9, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
0 votes
1 answer

Browse Categories