Skip to content

Instantly share code, notes, and snippets.

@mikofski
Last active June 26, 2024 01:03
Show Gist options
  • Save mikofski/1517ef35cd5fadafc1ebf2f5191e8ead to your computer and use it in GitHub Desktop.
Save mikofski/1517ef35cd5fadafc1ebf2f5191e8ead to your computer and use it in GitHub Desktop.
vertical_pv.ipynb
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@tadatoshi
Copy link

First of all, thank you for this Gist.

I have found two issues purely on programming side. I write how usually done below.

  1. Slicing on Pandas DataFrame/Series Index: You can use loc.
    (I remember that there used be a warning when loc is not used.)
    e.g. sp.loc[july(4)] instead of sp[july(4):july(4)]
    Also,
    ac_output.loc[july(1):july(5)] instead of ac_output[july(1):july(5)]

  2. Avoiding side effect of data modification in Python function: You can deep copy DataFrame inside the function.
    Inside do_the_magic function:
    # This performs deep copy of the DataFrame:
    my_weather_data_copy = my_weather_data.copy()
    # shift the weather times to interval centers to make pandas work more easily
    my_weather_data_copy.index = TIMES
    # Use this copy in the rest of the function
    ...
    # No need to reassign original times to weather_data.index at the end of function
    instead of:
    weather_times = my_weather_data.index
    # shift the weather times to interval centers to make pandas work more easily
    my_weather_data.index = TIMES
    ## The code above causes side effect of modifying weather_data outside the function.
    ...
    # weather_data scope exists outside this function, we stole the
    # references, so now we need to return it to its original state
    weather_data.index = weather_times

I hope this helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment