Last active
July 24, 2018 23:53
-
-
Save rpanai/ea9828f92b0ba6a4c6e8f5df2f081386 to your computer and use it in GitHub Desktop.
Fast Flexible Easy Pandas
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| import numpy as np | |
| # define diz | |
| diz_prices = {0:12, 1:20, 2:28} | |
| out = pd.DataFrame(index=np.arange(25)) | |
| out["price"] = np.digitize(out.index.values , bins=[7,17,24]) | |
| out["price"] = out["price"].map(diz_prices) | |
| diz = out.to_dict()["price"] | |
| def apply_tariff_vectorize(df, diz): | |
| df['cost_cents'] = df["date_time"].dt.hour.map(diz) * df["energy_kwh"].values | |
| df = pd.read_csv("https://raw.githubusercontent.com/realpython/materials/master/pandas-fast-flexible-intuitive/tutorial/demand_profile.csv", | |
| parse_dates=["date_time"]) | |
| apply_tariff_vectorize(df, diz) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What is that mean np.arange(25) , why we need array 0 to 25??