下变换(MS - >日期时间 - > CONVER时区)需要很长的时间来运行(4分钟),可能是因为我用的大数据帧的工作:加快时间戳操作
for column in ['A', 'B', 'C', 'D', 'E']:
# Data comes in unix time (ms) so I need to convert it to datetime
df[column] = pd.to_datetime(df[column], unit='ms')
# Get times in EST
df[column] = df[column].apply(lambda x: x.tz_localize('UTC').tz_convert('US/Eastern'))
有任何方式来加快它?我是否已经以最有效的方式使用Pandas数据结构和方法?
谢谢,虽然第一个选项似乎不适用于** 0.14.1 **。我在'tz_localize'中得到一个错误,说'TypeError:index不是有效的DatetimeIndex或PeriodIndex'。 – 2014-09-04 12:53:38
Andy,我的'.dt'命名空间下没有'tz_localize'。这是否实施?这将是超级有用的。 – TomAugspurger 2014-09-04 14:39:44
@ user815423426这很奇怪,这听起来像列没有正确地转换为日期,因此DatetimeIndex失败...做了你的to_datetime行工作 - 你检查结果dtype?这可能有点费劲。 – 2014-09-04 17:25:38