Reputation: 79
I have a dictionary with the key is the date and the value is revenue from the date, as shown in the picture
Dictionary data:
I also have a dataframe of the currency of each date, as shown in the picture
Dataframe of the currency:
So, how to make a dataframe with 2 columns. The first columns is the date, and the second column is the converted revenue
Expected Values:
Date | Revenue |
---|---|
2019-11-01 | 5853302 |
2019-11-02 | 17415125 |
2019-11-03 | 19684777 |
... | ... |
2020-03-29 | 1227610 |
Upvotes: 1
Views: 243
Reputation: 41407
You can map()
the revenues by id
and multiply by idr
.
Assuming the revenue dictionary is named revenue
and the currency dataframe is named currency
:
result = pd.DataFrame({
'Date': currency.id,
'Revenue': currency.id.astype(str).map(revenue) * currency.idr,
})
# Date Revenue
# 2019-11-01 5.853307e+06
# 2019-11-02 1.741513e+07
# 2019-11-03 1.968478e+07
# 2019-11-04 2.132557e+07
# ...
Upvotes: 1
Reputation: 446
this should work: (here df1 is your original dataframe)
df2 = pd.DataFrame(columns=['date','revenue'])
df2['date'] = df1['date']
df2['revenue'] = df1['idr'].apply(lambda x: x*10) #replace x*10 with whatever other calculation you want to do
Upvotes: 0