如何使用 pandas 重新采样从 CSV 加载的日期列?
How to resample date column loaded from CSV with pandas?
我从 CSV 加载了这些数据。
Date X Y Z
0 2015-11-30 20:23:05.556 281.764900 -43.895060 8.714666
1 2015-11-30 20:23:05.757 192.519990 -44.636436 1.720552
2 2015-11-30 20:23:05.958 149.030600 -45.098050 1.958352
3 2015-11-30 20:23:06.171 140.707600 -44.622448 1.510729
4 2015-11-30 20:23:06.366 139.154890 -45.154003 4.783974
5 2015-11-30 20:23:06.564 138.875140 -44.790306 2.266093
6 2015-11-30 20:23:06.766 138.357570 -44.048930 4.210457
7 2015-11-30 20:23:06.967 136.846830 -45.909367 -2.196152
8 2015-11-30 20:23:07.168 137.322430 -45.126026 0.139882
9 2015-11-30 20:23:07.369 137.322430 -45.349840 0.587506
10 2015-11-30 20:23:07.573 132.552460 -48.455223 5.259574
列的 dtypes
是这些:
Date datetime64[ns]
X float64
Y float64
Z float64
dtype: object
我想对 Date
列重新采样,例如以百毫秒为单位。我尝试使用
something.unstack().Date.resample('100L').Date.stack()
但是写错了
TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex
你知道怎么做吗?
df.index = pd.to_datetime(df['Date'], format='%Y-%m-%d %H:%M:%S.%f')
df = df.drop('Date', axis=1)
df = df.resample('resamplestring', how='mean')
我从 CSV 加载了这些数据。
Date X Y Z
0 2015-11-30 20:23:05.556 281.764900 -43.895060 8.714666
1 2015-11-30 20:23:05.757 192.519990 -44.636436 1.720552
2 2015-11-30 20:23:05.958 149.030600 -45.098050 1.958352
3 2015-11-30 20:23:06.171 140.707600 -44.622448 1.510729
4 2015-11-30 20:23:06.366 139.154890 -45.154003 4.783974
5 2015-11-30 20:23:06.564 138.875140 -44.790306 2.266093
6 2015-11-30 20:23:06.766 138.357570 -44.048930 4.210457
7 2015-11-30 20:23:06.967 136.846830 -45.909367 -2.196152
8 2015-11-30 20:23:07.168 137.322430 -45.126026 0.139882
9 2015-11-30 20:23:07.369 137.322430 -45.349840 0.587506
10 2015-11-30 20:23:07.573 132.552460 -48.455223 5.259574
列的 dtypes
是这些:
Date datetime64[ns]
X float64
Y float64
Z float64
dtype: object
我想对 Date
列重新采样,例如以百毫秒为单位。我尝试使用
something.unstack().Date.resample('100L').Date.stack()
但是写错了
TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex
你知道怎么做吗?
df.index = pd.to_datetime(df['Date'], format='%Y-%m-%d %H:%M:%S.%f')
df = df.drop('Date', axis=1)
df = df.resample('resamplestring', how='mean')