python - 如何有效地将函数应用于大熊猫系列?
问题描述
我有一个以 unix 时间为开始日期的 pandas 系列时间样本。每个时间样本为 x * 1 / 512,因此时间戳 0 = 0,时间戳 2 = 1 / 512 或 0.00195,时间戳 3 = 2 / 512 或 0.0039。我需要将开始日期(偏移量)添加到所有值并将结果转换为本地时间(PST)。我有以下
times = np.arange(0, 3600, 1/512)
tz = 'US/Pacific'
offset = 1569603352 # 2019-09-27 09:57 (or something similar)
srs = pd.Series(times)
srs.apply(lambda t: pd.to_datetime(offset + t, unit='s', utc=True) \
.tz_convert(tz))
有什么方法可以加快速度吗?我有一堆强大的 GPU 和大约 50 个线程,因此可以使用多线程或处理。
解决方案
我将通过删除加快速度apply
pd.to_datetime(offset + srs, unit='s', utc=True).dt.tz_convert(tz)
推荐阅读
- python - 粗糙集:Python 中的快速归约/特征选择
- java - Java:将 double 转换为 int > Integer.MAX_VALUE
- javascript - 在 Prod env 中将 isDevMode 传递给 forRoot 抛出错误
- java - 一个组件需要一个名为“userService”的 bean,但找不到该 bean
- scala - WriterT 还是 ReaderWriterStateT?
- javascript - Json 返回 null JavaScript
- date - spring boot 测试 h2 data.sql 错误的语言环境日期格式
- apache-kafka - Apache Kafka Connect 根据记录值路由消息
- python - 如何在 Python 中使用正则表达式从字符串中删除两个“下划线数字”子字符串?
- mapbox - 自定义矢量切片与 mapbox 中由 geojson 源制作的切片不匹配