Converting with Python forex modul

问题内容:

I have a large dataframe with dates (datetime64[ns] format) and values of JPY. I want to convert the JPY values of the dataframe for each specific time to USD using the python forex modul. The forex modul needs datetime.datetime / date_obj as input, so I tried to convert the datetime64 column to datetime.datetime dataframe, but this seems to be impossible.

>>>import pandas as pd
>>>import numpy as np

>>>from datetime import datetime
>>>from forex_python.converter import get_rate

>>>from forex_python.converter import CurrencyRates
>>>c = CurrencyRates()

>>>import datetime

>>>dfconverted = c.convert('JPY', 'USD', df['Money_JPY'], datetime_object)

I’ve tried to convert The df[‘Date’] into a list of datetime.datetime values, but I don’t know to use this list for the conversion with the forex modul.

>>>df['Date'] = pd.DatetimeIndex(df['Date'])
>>>pd.DatetimeIndex(df['Date']).to_pydatetime().tolist()

问题评论:

原文地址:

https://stackoverflow.com/questions/47756803/converting-with-python-forex-modul

添加评论