1 ,2 3 is a Month (Miesiac) and "123","222",.... is Price(cena) cena_dict = { 1 : "123", 2 : "222", 3 : "2131231" }
data = {
"Zrodlo" : ["A","B","B"],
"Wartosc" : [100,200,300],
"MWh" : [10,20,10],
"Miesiac" : [1,2,5]
}
first way - work correct
df = pd.DataFrame(data)
df["Test"] = np.where(df["Zrodlo"]=="A",
np.divide(df["Wartosc"],df["MWh"]),
df["Miesiac"].map(lambda x: cena_dict.get(x,"Nie znalazlem")))
second way doesn't work
frame with data:
ceny = {
"Zrodlo" : ["A","B","B"],
"Cena" : [123,222,333],
"Miesiac" : [1,2,5]
}
df_ceny = pd.DataFrame(ceny)
df = pd.DataFrame(data)
df["Test"] = np.where(df["Zrodlo"]=="A",
np.divide(df["Wartosc"],df["MWh"]),
df["Miesiac"].map(lambda x: df_ceny.loc[df_ceny["Miesiac"]==x,"Cena"]))
print(df)
In second option I would like use .loc couse in that case I recived date in DateFrame and dictionary (way first) doesnt work
Thanks you