Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Pandas input #8

Open
dean-sh opened this issue Sep 26, 2024 · 0 comments
Open

Feature request: Pandas input #8

dean-sh opened this issue Sep 26, 2024 · 0 comments

Comments

@dean-sh
Copy link

dean-sh commented Sep 26, 2024

Hello,
Thank you for this!

Would be happy if I could input a pandas series with datetime64 format / datetime index and get the settlement period pandas series as an output. Perhaps there could be a more efficient way to handle a long time series other than running .apply to every row.

With the current implementation, such effect can be (inefficiently) achieved like so:

from sp2ts import ts2sp, to_unixtime

df["datetime"] = pd.to_datetime(
    df.index, utc=True
).tz_convert("Europe/London")

# Convert the datetime column to Unix time using a vectorized operation
unix_times = df["datetime"].apply(to_unixtime)

# Apply the ts2sp function to the entire Unix time series at once
dates, settlement_periods = zip(*unix_times.apply(ts2sp))

df["date"] = dates
df["sp"] = settlement_periods
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant