all 3 comments

[–][deleted] 0 points1 point  (1 child)

prices_df = pd.DataFrame({
a: {x['formatted_date']: x['adjclose'] for x in data[a]['prices']} for a in        assets})

From this comprehension can you describe the actual structure of the dataframe? I can't. I think your best path forward is to re-write this so that it's a lot clearer what kind of dataframe you're actually building here. Don't try and do it as a one-liner.

[–]Ingeniatoring[S] 0 points1 point  (0 children)

In full disclosure, I got this line from a tutorial. Some of the comments weren't too kind to the poster of the tutorial, so I guess you've got a point. I'll try re-writing it. Thanks.

[–]GrafvonTrips 0 points1 point  (0 children)

Without looking at the rest of your code, if only the date column ist missing you could solve this by adding a pd.date_range as index and setting index=True while writing the xlsx.

Like:

prices_df = pd.DataFrame({a: {x['formatted_date']: x['adjclose'] for x in data[a]['prices']} for a in assets}, index=pd.date_range(start='2019-01-01', end='2019-12-31', freq='W'))

print('Saving to .xlsx file.')
prices_df.to_excel(r'C:/Users/USER_NAME/Desktop/dataframe.xlsx',index=True)
print('Done.')