HereItIs
HereItIs

Reputation: 154

Variable not defined during data analysis

I'm new to programming and I've looked at previous answers to this question but none seem relevant to this specific query.

I'm learning to analyse data with python.

This is the code:

import pandas as pd

import os

os.chdir('/Users/Benjy/Documents/Python/Data Analysis Python')

unames = ['user_id', 'gender', 'age', 'occupation', 'zip']
users = pd.read_table('ml-1m/users.dat', sep='::', header = None, names = unames)

rnames = ['user_id', 'movie_id', 'rating', 'timestamp'] 
ratings = pd.read_table('ml-1m/ratings.dat', sep='::', header = None, names = rnames)

mnames = ['movie_id', 'title', 'genres']
movies = pd.read_table('ml-1m/movies.dat', sep='::', header = None, names = mnames)

data = pd.merge(pd.merge(ratings, users), movies)


mean_ratings=data.pivot_table('ratings',rows='title', cols='gender',aggfunc='mean')

I keep getting an error saying mean_ratings is not defined...but surely it is defined in the last line of code above?

Upvotes: 0

Views: 177

Answers (1)

shivsn
shivsn

Reputation: 7828

I think this will work: mean_ratings=data.pivot_table('rating',index='title',columns='gender',aggfunc='‌​mean')

Upvotes: 0

Related Questions