<jupyter_start><jupyter_text>Export Weather Data to Excel<jupyter_code>all_results[0]
test = all_results[1]
test.columns.duplicated()
for i, r in enumerate(all_results):
    if not isinstance(r,str):
        try:
            all_results[i] = r.loc[:,~r.columns.duplicated()]
        except Exception as e:
            print(e)
            print(i)
            print(r)
            break
len(all_results)
NA_indices = [i for i,e in enumerate(all_results) if isinstance(e,str)]
NA_indices
new_results = []
for i,df in enumerate(all_results):
    if i in NA_indices:
        new_results.append(df)
        continue
        
    df['maxtempC']=df['maxtempC'].apply(int)
    df['mintempC']= df['mintempC'].apply(int)
    maxs = np.asarray(list(df["maxtempC"]))
    mins = np.asarray(list(df["mintempC"]))
    avg = np.add(maxs, mins)
    avg = np.true_divide(avg,2)
    df['avgtempC'] = avg.tolist()
    
    new_results.append(df)
template = pd.read_excel(template_file_name, index = False)
date_columns = list(template.columns[-10:])
date_columns
def generate_excel_tabs(feature_names, results):
    output = [pd.read_excel(template_file_name) for i in range(len(feature_names))]
    column_names = template.columns
    for i, df in enumerate(results):
        if i in NA_indices:
            continue
        for k, feature_name in enumerate(feature_names):
            values = list(df.loc[:,feature_name])
            for j, date in enumerate(date_columns):
                try:
                    output[k][date][i] = values[j]
                except IndexError as e:
                    print(feature_name)
                    print ("j:",j, " date:",date, "i:", i)
                    print(e)
    
    return output
results = new_results
features = ["maxtempC","mintempC","avgtempC","cloudcover","humidity","precipMM","pressure",
           "windspeedKmph","totalSnow_cm",'sunHour','moon_illumination','moonrise',
           'moonset','sunrise','sunset','DewPointC','FeelsLikeC',
            'WindChillC','WindGustKmph','visibility','winddirDegree',
          ]
len(features)

excel_output = generate_excel_tabs(features, results)
writer = pd.ExcelWriter('weather data.xlsx', engine='xlsxwriter')
for i, sheet in enumerate(excel_output):
    sheet.to_excel(writer, sheet_name = features[i], index = False)
writer.save()<jupyter_output><empty_output><jupyter_text>Testing<jupyter_code>LA_coords = "34.05,-118.25"
start = "11-APR-2020"
end = "12-APR-2020"
result = retrieve_hist_data(api_keys[0],
                                [LA_coords],
                                start,
                                end,
                                frequency,
                                location_label = False,
                                export_csv = False,
                                store_df = True)
result[0]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12622377622377623, 'fraction_numerical': 0.009790209790209791, 'mean_word_length': 2.446987951807229, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '265789', 'license': 'MIT', 'n_tokens_mistral': 959, 'n_tokens_neox': 908, 'n_words': 163, 'path': 'WeatherDataCollection/Weather Data Collection for Upload.ipynb', 'repo_name': 'marichig/weather-conditions-COVID19', 'size': '2860'}