Jul-14-2020, 09:56 PM
I have a set of data that can come through a stock data API, the amount of data and how stocks is depending on users' requests. The data I receive from the API comes in as a dictionary.
Example:
So that the dataframe looks something like this?
I have tried something like this, where I called the dictionary the API provides dataToday:
I know it might be a stupid or a easy question, all help is appreciated. Thanks! :)
Example:
{'YAR': last date 2020-07-10 336.4 2020-07-13 344.0 2020-07-14 344.3, 'DNB': last date 2020-07-10 129.60 2020-07-13 142.45 2020-07-14 145.50, 'NHY': last date 2020-07-10 27.35 2020-07-13 28.56 2020-07-14 28.50}Is it possible to write a for loop in Python where for every key in the dictionary it will create a new pandas data frame row with its value and date as index?
So that the dataframe looks something like this?
I have tried something like this, where I called the dictionary the API provides dataToday:
tickerlist = ['YAR','DNB','NHY'] df = pd.DataFrame(columns=tickerlist) for ticker in tickerlist: df = df.append(pd.DataFrame.from_dict(dataToday[ticker]))But this gives me a data frame which looks like this:
I know it might be a stupid or a easy question, all help is appreciated. Thanks! :)