Created
December 31, 2022 13:06
-
-
Save sertalpbilal/c2412e1594d04ff8d4a37b4c46686239 to your computer and use it in GitHub Desktop.
Kiwi data to Review converter
This file contains 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
def get_data_kiwi(target, can_use_cache=False): | |
if can_use_cache: | |
if os.path.exists(target): | |
return pd.read_csv(target) | |
raw_data = pd.read_csv("https://github.com/theFPLkiwi/webpage/raw/main/data/Projected_FPL_2223.csv") | |
# ("https://raw.githubusercontent.com/theFPLkiwi/webpage/main/data/Projected_FPL_2122.csv") | |
first_gw = int(raw_data.keys()[9]) | |
last_gw = 38 | |
col_count = last_gw - first_gw + 1 | |
raw_data.iloc[:, 9:38-9+1] | |
main_values = raw_data.iloc[:, 0:5].copy() | |
main_values['Pos'] = main_values['Pos'].str[0] | |
main_values['Value'] = main_values['Price'] | |
# main_values.columns= main_values.columns.str.lower() | |
xmin_values = raw_data.iloc[:, 9:9+col_count].copy() | |
xmin_values = xmin_values.add_suffix("_xMins") | |
xp_start = list(raw_data).index('xPts') | |
xp_values = raw_data.iloc[:, xp_start+1:xp_start+col_count+1] | |
xp_values.columns = [i[0] for i in xp_values.columns.str.split('.')] | |
xp_values = xp_values.add_suffix("_Pts") | |
with open('data/elements.json') as f: | |
elements_data = json.load(f) | |
name_dict = {i['id']: i['web_name'] for i in elements_data} | |
main_values['Name'] = main_values['ID'].map(name_dict) | |
kiwi_data = pd.concat([main_values, xmin_values, xp_values], axis=1) | |
kiwi_data['review_id'] = kiwi_data['ID'] | |
kiwi_data.set_index('ID', inplace=True) | |
kiwi_data.sort_index(inplace=True) | |
kiwi_data.to_csv(target) | |
return kiwi_data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment