I am getting the following error:
TypeError: cannot concatenate object of type '<class 'str'>'; only Series and DataFrame objs are valid
Traceback (most recent call last):
File "/var/task/etd.py", line 77, in lambda_handler
data = pd.concat(concated_data, ignore_index=True)
In the following block:
for idx, day_row in curr_df.iterrows():
av_last_month, rate_end_last_mon = last_months_avs(df_to_date, day_row['From_Currency'], day_row['To_Currency'], day_row['Obs_Date'])
concated_data = ({'Obs_Date': day_row['Obs_Date'], 'From_Currency': day_row['From_Currency'],
'To_Currency': day_row['To_Currency'], 'Rate': day_row['Rate'],
'PE_Rate': av_last_month, 'Mon_End_Rate': rate_end_last_mon})
data = pd.concat(concated_data, ignore_index=True)
new_df = pd.DataFrame(data)
>Solution :
One of your values is a string and not a Series or a DataFrame:
concated_data = ({'key1': pd.Series(), 'key2': pd.Series()})
pd.concat(concated_data, ignore_index=True)
# Output
Series([], dtype: object)
However:
concated_data = ({'key1': pd.Series(), 'key2': pd.Series(), 'key3': ''})
pd.concat(concated_data, ignore_index=True)
# Output
...
TypeError: cannot concatenate object of type '<class 'str'>'; only Series and DataFrame objs are valid
To debug, try:
for key, val in concated_data.items():
print(key, type(val))
# Output
key1 <class 'pandas.core.series.Series'>
key2 <class 'pandas.core.series.Series'>
key3 <class 'str'>
Note: I think you should also use axis=1 as argument of pd.concat.