numpy - Python: pivot table error -
i'm trying find average hourly trips
on weekends , weekdays both "annual members" , "short-term pass holder"
data frame info:
datetimeindex: 7795 entries, 2014-10-13 2015-10-12 data columns (total 4 columns): (hour, ) 7795 non-null int64 (trip_id, annual member) 7795 non-null float64 (trip_id, short-term pass holder) 7795 non-null float64 (weekend, ) 7795 non-null bool
data frame looks in attached image
i attempted below code, not working by_hour.pivot_table(index=['weekend','hour'],aggfunc ='mean',columns=['annual member','short-term pass holder'])
error thrown is:
attributeerror: 'numpy.ndarray' object has no attribute 'start'
edit: posting completed code:
%matplotlib inline import matplotlib.pyplot plt import pandas pd import numpy np import seaborn sns; sns.set() trips = pd.read_csv('2015_trip_data.csv', parse_dates=['starttime', 'stoptime'], infer_datetime_format=true) ind = pd.datetimeindex(trips.starttime) trips['date'] = ind.date.astype('datetime64') trips['hour'] = ind.hour by_date = trips.pivot_table(index=['date'],values =['trip_id'], columns='usertype', aggfunc ='count') by_weekday=by_date.groupby([by_date.index.year,by_date.index.dayofweek]).mean() by_hour = trips.pivot_table(index =['date','hour'], columns =['usertype'], values =['trip_id'], aggfunc ='count').fillna(0).reset_index('hour')
Comments
Post a Comment