0

I have to do the tasks below, but some parts do not work out properly. Here are the steps:

  1. Converting a dataframe with unix timestamps to a dataframe with datetime values, works with the following code: datetime_df = pd.to_datetime(unix_df, unit='s')
  2. Resampling the datetime with smpl = datetime_df[0].resample('10min')
  3. Converting it back to unix timestamp format with: unix_df = datetime_df.astype(np.int64) // 10 ** 9

Step 1 and 3 work, but step 2 doesn't work because Python tells me it needs a DateTimeIndex and I don't know how to set it. The strange thing is that the index completely disappears after to_datetime, so I tried creating a list and then making a dataframe from it again, but it still didn't work. Somebody can help me?

sunwarr10r
  • 4,420
  • 8
  • 54
  • 109
  • `datetime_df.set_index('your_column', inplace=True)` where 'your_column' is the name of the datetime column – juanpa.arrivillaga Dec 13 '16 at 22:27
  • Thank you @juanpa.arrivillaga. Unfortunately I get the following error: AttributeError: 'Series' object has no attribute 'set_index' – sunwarr10r Dec 13 '16 at 22:30
  • then you are working with a Series, not a DataFrame. – juanpa.arrivillaga Dec 13 '16 at 22:32
  • `to_datatime` makes a series of the frame. I can convert it back to a frame with `frame = pd.DataFrame(seriesobject)` but I still can not use resample on it and get the following TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of 'RangeIndex' – sunwarr10r Dec 13 '16 at 22:37
  • the use the code I showed you to set the index on your datframe – juanpa.arrivillaga Dec 13 '16 at 22:38
  • 1
    Please include a sample of your data: read [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) – Julien Marrec Dec 14 '16 at 00:38

0 Answers0