Sort by

recency

|

18 Discussions

|

  • + 0 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")
    
  • + 1 comment
    import numpy as np
    import pandas as pd
    
    N = int(input())
    input()
    
    data = []
    missing = []
    for i in range(N):
        line = input()
        year, month, t_min, t_max = line.split()
        if 'Missing' in t_min:
            t_min = np.NaN
            missing.append((i,'t_min'))
        if 'Missing' in t_max:
            t_max = np.NaN
            missing.append((i,'t_max'))
        data.append([float(t_min), float(t_max)])
        
    df = pd.DataFrame(data, columns=['t_min','t_max'])
    df = df.interpolate('cubic', limit_direction='both')
    
    for i,col in missing:
        print(round(df.iloc[i][col],2))
    
  • + 0 comments

    Is this temperation prediction work good? As i go for wood cutting along my Power Equipment.

  • + 2 comments

    Simple solution with interpolation

    import pandas as pd
    
    N = int(input())
    
    columns = input().split()
    
    df = pd.DataFrame(columns=columns)
    
    for i in range(N):
        df.loc[i, :] = input().split()
        
    df.tmax = pd.to_numeric(df.tmax, errors='coerce')
    df.tmin = pd.to_numeric(df.tmin, errors='coerce')
    
    tmax_missing = df.tmax.isna()
    tmin_missing = df.tmin.isna()
    
    tmax_interp = df.tmax.interpolate(method='cubic')
    tmin_interp = df.tmin.interpolate(method='cubic')
    
    for i in range(df.shape[0]):
        if tmax_missing[i]:
            print(tmax_interp[i])
        if tmin_missing[i]:
            print(tmin_interp[i])
    
  • + 0 comments

    Hi, Im getting this compiler message:

    Custom checker Failed: Success
    

    And this Custom Checker Error Message at the bottom of the test case:

    Traceback (most recent call last):
      File "/custom-D5UXWlZg7Y7Vtpf6S1QY/solution.py", line 183, in <module>
        run_custom_checker(t_obj, r_obj)
      File "/custom-D5UXWlZg7Y7Vtpf6S1QY/solution.py", line 94, in run_custom_checker
        return WA(r_obj,score)
      File "/custom-D5UXWlZg7Y7Vtpf6S1QY/solution.py", line 44, in WA
        obj.message = "Wrong Answer\n" + msg
    TypeError: coercing to Unicode: need string or buffer, float found
    

    help anyone! just really curious to see if my code is right!