Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graphing Data after Filling Nan Values #7

Open
raphillips opened this issue May 6, 2014 · 0 comments
Open

Graphing Data after Filling Nan Values #7

raphillips opened this issue May 6, 2014 · 0 comments

Comments

@raphillips
Copy link
Contributor

Hi, I'm stuck. I used the following to fill in Nan values:

import pandas as pd
import numpy as np
from matplotlib import pyplot as plt
from sklearn.linear_model import LinearRegression
from sklearn.feature_selection import f_regression
from sklearn.metrics import mean_squared_error, mean_absolute_error
%pylab inline

male = titanic[titanic['sex'] == "male"]
female = titanic[titanic['sex'] == "female"]

male = male.fillna(male.mean())
female = female.fillna(male.mean())

Then I was able to graph the values using the following:
male['age'].hist()
female['age'].hist()

But when I use this method to graph, I am able to graph the male age population but I get an error for the female graph that reads: "KeyError: 0L"

fig = plt.figure()
fig.set_figwidth(20)
fig.set_figheight(8)

ax1 = fig.add_subplot(1,2,1)
ax1.hist(male['age'])
plt.title('Male Age')
plt.xlabel('Age')
plt.ylabel('Number of Occurences')
plt.grid(True)

ax2 = fig.add_subplot(1,2,2)
ax2.hist(female['age'])
plt.title('Female Age')
plt.xlabel('Age')
plt.ylabel('Number of Occurences')
plt.grid(True)

Can you please help!

Additionally, the reason why I'm filling in Nan values is because I couldn't graph the following: plt.hist(titanic['age'])
because I was getting an error message that stated: "AttributeError: max must be larger than min in range parameter."

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant