I want to merge rows in csv files by matching the id with a given dictionary.
I have a dictionary: l= {2.80215: [376570], 0.79577: [378053], 22667183: [269499]}
I have a csv file.
A B C D
2000-01-03 -0.59885 -0.18141 -0.68828 -0.77572
2000-01-04 0.83935 0.15993 0.95911 -1.12959
2000-01-05 2.80215 -0.10858 -1.62114 -0.20170
2000-01-06 0.71670 -0.26707 1.36029 1.74254
2000-01-07 -0.45749 0.22750 0.46291 -0.58431
2000-01-10 -0.78702 0.44006 -0.36881 -0.13884
2000-01-11 0.79577 -0.09198 0.14119 0.02668
2000-01-12 -0.32297 0.62332 1.93595 0.78024
2000-01-13 1.74683 -1.57738 -0.02134 0.11596
The output should be :
A B C D E F
2000-01-03 -0.59885 -0.18141 -0.68828 -0.77572 0
2000-01-04 0.83935 0.15993 0.95911 -1.12959 0
2000-01-05 2.80215 -0.10858 -1.62114 -0.20170 376570
2000-01-06 0.71670 -0.26707 1.36029 1.74254 0
2000-01-07 -0.45749 0.22750 0.46291 -0.58431 0
2000-01-10 -0.78702 0.44006 -0.36881 -0.13884 0
2000-01-11 0.79577 -0.09198 0.14119 0.02668 378053
2000-01-12 -0.32297 0.62332 1.93595 0.78024 0
2000-01-13 1.74683 -1.57738 -0.02134 0.11596 0
I tried to do it this way:
import pandas
data = panda.read_csv("thisfiel.csv")
data["F"] = data["B"].apply(lambda x: l[x])
But I couldn't get the aimed results.