Here is the data (power outages in LA after Hurricane Isaac): https://github.com/geomando/code_share/blob/master/OutageData_MasterList.csv
Here is my attempt:
outage_data = read_csv('OutageData_MasterList.csv', parse_dates = [[4,5]])
# calculate elapsed time and create a new df column
start_date_time = outage_data.index[0].to_datetime()
outage_date_time = outage_data.index.to_pydatetime()
outage_data['Elapsed Time'] = outage_date_time - start_date_time
# create groups by parish
outage_data_parish = outage_data.groupby('Parish')
# plot -- clearly matplotlib doesn't like timedelta
for name, group in outage_data_parish:
plt.plot(group['Elapsed Time'], group['Outage Percent'])
TypeError: float() argument must be a string or a number
Thoughts? thanks!
Scott
Hey all,Sorry to drop in on the thread out of nowhere, but google sent me here and I thought it wouldn't hurt to ask... So, I tried this suggestion, however, I think that there were some significant changes in the timedelta64 dtype from numpy 1.6 to 1.7 that don't allow this to work.After downloading the data and attempting to convert using Jeff's suggestion, as:outage_data['diff']=outage_data['Date_Time']-outage_data['Date_Time'][0]
outage_data['ddiff'] = outage_data['diff'].apply(lambda x: float(x.item().total_seconds())/(3600*24)) outage_data.dtypesI get hit with the following error:
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-4-6d80c1d26eb6> in <module>() 1 outage_data['diff']=outage_data['Date_Time']-outage_data['Date_Time'][0] ----> 2 outage_data['ddiff'] = outage_data['diff'].apply(lambda x: float(x.item().total_seconds())/(3600*24)) 3 outage_data.dtypes /Users/nehalecky/Documents/projects/python/pandas/pandas/core/series.pyc in apply(self, func, convert_dtype, args, **kwds) 2449 values = lib.map_infer(values, lib.Timestamp) 2450 -> 2451 mapped = lib.map_infer(values, f, convert=convert_dtype) 2452 if isinstance(mapped[0], Series): 2453 from pandas.core.frame import DataFrame /Users/nehalecky/Documents/projects/python/pandas/pandas/lib.so in pandas.lib.map_infer (pandas/lib.c:42231)() <ipython-input-4-6d80c1d26eb6> in <lambda>(x) 1 outage_data['diff']=outage_data['Date_Time']-outage_data['Date_Time'][0] ----> 2 outage_data['ddiff'] = outage_data['diff'].apply(lambda x: float(x.item().total_seconds())/(3600*24)) 3 outage_data.dtypes AttributeError: 'long' object has no attribute 'total_seconds'FYI, I am running on pandas developer build:1.7.1 0.12.0.dev-5afb0ebAny suggestions?Thanks much,Nicholaus