Repository navigation
Replies: 1 comment
|
The key detail in your screenshot is For the string input shown in the screenshot, perform the Pendulum operation inside the same callback, before pandas collects its results: import pandas as pd
import pendulum
source = pd_df["scheduledEventTimesInUtc"]
pd_df["plus_7_days"] = source.apply(
lambda value: (
pd.NaT
if pd.isna(value)
else pendulum.parse(value).add(days=7)
)
)The final column may again be a pandas datetime column; that is fine if the calculation is complete. Pendulum's add/subtract methods return new values, so remember to assign the result. If you need to store actual Pendulum objects for several later Pendulum-specific operations, explicitly construct an object Series from those objects: values = [
None if pd.isna(value) else pendulum.parse(value)
for value in source
]
pd_df["pendulum"] = pd.Series(
values, index=pd_df.index, dtype=object
)
pd_df["plus_7_days"] = pd.Series(
[None if value is None else value.add(days=7) for value in values],
index=pd_df.index,
dtype=object,
)Specify For only the UTC +7-day calculation, pandas also has a direct vectorized expression: pd_df["plus_7_days"] = pd.to_datetime(source, utc=True) + pd.Timedelta(days=7)That example adds seven elapsed days to UTC timestamps. Calendar operations in another timezone can have different daylight-saving semantics. I also omitted These examples address the pandas traceback shown. The object/callback approach is Python-level work rather than a vectorized Pendulum engine. I checked the documented APIs but have not executed your data. |
Uh oh!
There was an error while loading. Please reload this page.
Issue
Hello! I have tried many things to convert an entire column to a pendulum datetime type to be able to perform operations on it. I have tried in Polars and Pandas. I have converted it to a string and a timestamp with pendulum commands, but neither of these allows me to do operations on it. See example below. How do I perform pendulum operations on entire columns?
All reactions