简体   繁体   English

如何有效地将 function 应用于大型 pandas 系列?

[英]How to apply a function to a large pandas series efficiently?

I have pandas series of time samples with a start date in unix time.我有 pandas 系列时间样本,开始日期在 unix 时间。 Each time sample is x * 1 / 512 so time stamp 0 = 0, time stamp 2 = 1 / 512 or 0.00195, time stamp 3 = 2 / 512 or 0.0039.每个时间样本为 x * 1 / 512,因此时间戳 0 = 0,时间戳 2 = 1 / 512 或 0.00195,时间戳 3 = 2 / 512 或 0.0039。 I need to add the start date (offset) to all values and convert the result to local time (PST).我需要将开始日期(偏移量)添加到所有值并将结果转换为本地时间(PST)。 I have the following我有以下

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))

is there some way to speed this up?有什么方法可以加快速度吗? I have a bunch of powerful GPUs and around 50 threads so multithreading or processing is available.我有一堆强大的 GPU 和大约 50 个线程,因此可以使用多线程或处理。

I will speed up by remove apply我将通过删除apply加快速度

pd.to_datetime(offset + srs, unit='s', utc=True).dt.tz_convert(tz)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM