You are viewing a single comment's thread. Return to all comments →
import pandas as pd import calendar method='cubic' order=None N = int(input()) headers = input().split() data = [input().split() for _ in range(N)] df = pd.DataFrame(data,columns = headers) df["date"] = df["yyyy"].str.strip()+" "+df["month"].str.strip() df["date"] = pd.to_datetime(df["date"]) df = df.drop(["yyyy","month"],axis=1) df["tmax_copy"] = df["tmax"] df["tmin_copy"] = df["tmin"] df["tmax_was_na"] = df["tmax"].apply(lambda x: True if "Missing" in x else False) df["tmin_was_na"] = df["tmin"].apply(lambda x: True if "Missing" in x else False) df["tmax"] = df["tmax"].apply(lambda x: None if "Missing" in x else x) df["tmin"] = df["tmin"].apply(lambda x: None if "Missing" in x else x) df.index = df["date"] df = df.drop("date",axis=1) df["tmax"] = df["tmax"].astype(float) df["tmin"] = df["tmin"].astype(float) df["tmax"] = df["tmax"].interpolate(method=method,order=order) df["tmin"] = df["tmin"].interpolate(method=method,order=order) df_fin = df[df["tmax_was_na"]|df["tmin_was_na"]][["tmin","tmax","tmin_copy","tmax_copy"]] df_final = pd.DataFrame() df_final2 = pd.DataFrame() df_final["miss_val"] = df_fin[df_fin["tmax_copy"].str.contains("Missing")].tmax df_final["miss_name"] = df_fin[df_fin["tmax_copy"].str.contains("Missing")].tmax_copy df_final2["miss_val"] = df_fin[df_fin["tmin_copy"].str.contains("Missing")].tmin df_final2["miss_name"] = df_fin[df_fin["tmin_copy"].str.contains("Missing")].tmin_copy df_res = df_final.append(df_final2) df_res["miss_id"] = df_res["miss_name"].str.split("_").str[1].astype(int) print(*df_res.sort_values(by="miss_id").miss_val.to_list(),sep="\n")
Seems like cookies are disabled on this browser, please enable them to open this website
Day 7: Temperature Predictions
You are viewing a single comment's thread. Return to all comments →