2016-04-29 75 views
1
date   object 
lat   float64 
lon   float64 
speed  float64 
direction float64 

分組大GPS數據以我csv文件,日期是以下格式2016-04-29 11:45:21 的它表明日期作爲對象類型。每分鐘有超過10條記錄。所以,我想組合在一起,並應用每1分鐘GPS數據的平均速度。 我嘗試下面的代碼,其中數據文件是熊貓數據框。通過1分鐘

datafile.groupby(pd.TimeGrouper('1Min'))['speed'].mean() 

以下錯誤出現:

TypeError: axis must be a DatetimeIndex, but got an instance of 'Int64Index'


datafile.head編輯作爲註釋,然後後()顯示table outputtaxi table output after datafile.head()

現在我有1069條記錄,從06: 35:20至06:59:59。我需要找到每1個分鐘數據的速度平均

回答

1

則需要使用創建您的dataDateTimeIndex

df.index = pd.to_datetime(df.loc[: 'date'], format='%Y-%m-%d %H:%M:%S') 

然而,你也許可以利用內置的.read_csv()功能,使用parse_dates=Trueindex_col=0讀取date作爲index,然後解析index(假定日期是第一個column)。

+0

但日期顯示2013-01-16 06:35:20 1970-01-01 00:00:00。它不顯示2013 –

+0

將有助於顯示'df.head()'。查看更新 - 您可以優化您的'.read_csv()'以在閱讀時正確解析日期 - 查看文檔http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html – Stefan

+0

但還沒搞清楚。在這個幾小時內。當我使用上面的命令,然後輸出爲 1970-01-01 00:00:00.000000000 \t 2013-12-16 06:35:20 \t速度96 由1069條記錄組成。最後一條記錄是: 1970-01-01 00:00:00.000001068 \t 2013-12-16 06:59:59 \t速度78 爲此,如何按上述代碼進行分組後按1分鐘分組值.. –