Skip to content

Instantly share code, notes, and snippets.

@dldx
dldx / dataframecache.py
Created October 6, 2021 17:10
A way to permanently cache functions that return dataframes in parquet files, taking into account argument changes
import os
import inspect
import hashlib
import pandas as pd
class DataFrameCache(object):
"""Cache the results of a function that returns a dataframe by storing results as parquet files.
Usage:
We can make this file beautiful and searchable if this error is corrected: It looks like row 9 should actually have 12 columns, instead of 6 in line 8.
Country,Capacity (MW),Latitude,Longitude,LCOE Solar (2019),LCOE Solar (2040),LCOE Wind (2019),LCOE Wind (2040),solar_2019,solar_2040,wind_2019,wind_2040
China,30,32.93653,117.32370900000001,0.07639582577899201,0.030405538660039,0.068153522314145,0.041573648611629,3,1,3,2
China,50,31.735947999999997,118.488872,0.080917910533623,0.032205328392382,0.050893439299979006,0.031044997972987005,4,1,2,1
China,60,32.928397,117.285053,0.076525420055123,0.030457117181938997,0.054082052961128,0.032990052306287994,3,1,2,1
China,65,31.735947999999997,118.488872,0.080917910533623,0.032205328392382,0.050893439299979006,0.031044997972987005,4,1,2,1
China,60,31.717469,118.466699,0.08217073792804201,0.032703953695361,0.06772997758357,0.041315286325978,4,1,3,2
China,60,31.717469,118.466699,0.08217073792804201,0.032703953695361,0.06772997758357,0.041315286325978,4,1,3,2
China,60,31.717469,118.466699,0.08217073792804201,0.032703953695361,0.06772997758357,0.041315286325978,4,1,3,2
China,60,31.717469,118.466699,0.08217073792804201,0.0
We can make this file beautiful and searchable if this error is corrected: It looks like row 10 should actually have 26 columns, instead of 17 in line 9.
Plant,Latitude,Longitude,Capacity (MW),2019,2020,2021,2022,2023,2024,2025,2026,2027,2028,2029,2030,2031,2032,2033,2034,2035,2036,2037,2038,2039,2040
A.B. Brown Generating Station,37.9105389,-87.9230583,530,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3
AES Cayuga Generation Plant,42.6025444,-76.63597779999999,327,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3
AES Galabovo,42.1573,25.9084,670,0,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3
AES Hawaii Generation Plant,21.303111,-158.10805,204,0,0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3
AES Puerto Rico power station,17.9455578,-66.1494397,510,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3
AES Shady Point Generation Plant,35.191944,-94.6425,350,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
AES Somerset Generation Plant,43.3563833,-78.6035833,655,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3
AES Warrior Run Generation Plant Unit 1,39.595591,-78.745402,229,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3
APP Jinhuasheng Mill power station,31.306491,120.845299,80,3,3,3,3,3,3,3,3,3,3,3,3,
@dldx
dldx / .block
Last active June 15, 2021 02:38
Coal phaseout
license: mit
We can make this file beautiful and searchable if this error is corrected: It looks like row 10 should actually have 27 columns, instead of 1 in line 9.
Plant,Latitude,Longitude,2017,2018,2019,2020,2021,2022,2023,2024,2025,2026,2027,2028,2029,2030,2031,2032,2033,2034,2035,2036,2037,2038,2039,2040
A.B. Brown Generating Station,37.9105389,-87.9230583,530,530,530,530,530,265,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
AES Cayuga Generation Plant,42.6025444,-76.63597779999999,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
AES Galabovo,42.1573,25.9084,670,670,670,670,670,670,670,670,670,670,670,670,335,0,0,0,0,0,0,0,0,0,0,0
AES Hawaii Generation Plant,21.303111,-158.10805,102,102,102,102,102,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
AES Puerto Rico power station,17.9455578,-66.1494397,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
AES Shady Point Generation Plant,35.191944,-94.6425,350,350,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
AES Somerset Generation Plant,43.3563833,-78.6035833,655,655,655,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
AES Warrior Run Generation Plant Unit 1,39.595591,-78.745402,229,229,229,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
APP Jinhuasheng Mill po
We can make this file beautiful and searchable if this error is corrected: It looks like row 9 should actually have 27 columns, instead of 10 in line 8.
Plant,Latitude,Longitude,2017,2018,2019,2020,2021,2022,2023,2024,2025,2026,2027,2028,2029,2030,2031,2032,2033,2034,2035,2036,2037,2038,2039,2040
A.B. Brown Generating Station,37.9105389,-87.9230583,530,530,530,530,530,530,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
AES Cayuga Generation Plant,42.6025444,-76.63597779999999,327,327,327,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
AES Galabovo,42.1573,25.9084,670,670,670,670,670,670,670,670,670,670,670,670,670,670,670,670,670,670,670,670,670,670,670,670
AES Hawaii Generation Plant,21.303111,-158.10805,204,204,204,204,204,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
AES Puerto Rico power station,17.9455578,-66.1494397,510,510,510,510,510,510,510,510,510,510,510,0,0,0,0,0,0,0,0,0,0,0,0,0
AES Shady Point Generation Plant,35.191944,-94.6425,350,350,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
AES Somerset Generation Plant,43.3563833,-78.6035833,655,655,655,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
AES Warrior Run Generation Plant Unit 1,39.595591,-78.745402,229,229,229,229,229,229,229
@dldx
dldx / .block
Last active June 9, 2019 05:01
LRMC of coal plants
license: mit
@dldx
dldx / .block
Last active March 26, 2019 16:25
LRMC of coal plants
license: mit
@dldx
dldx / .block
Last active March 26, 2019 15:41
LRMC of coal plants in South Korea
license: mit
@dldx
dldx / .block
Last active December 10, 2018 16:19
fresh block
license: mit