Links

Transform dataframe to dict

Tags: #pandas #dict #snippet #yahoofinance #naas_drivers #operations #jupyternotebooks
Author: Florent Ravenel
With this template, you can convert dataframe to dictionary in pandas WITHOUT index

Input

Import libraries

from naas_drivers import yahoofinance

Input parameters

👉 Here you can change the ticker, timeframe and add moving averages analysis
ticker = "TSLA"
date_from = -100
date_to = 'today'

Model

Get dataframe from Yahoo Finance

df_yahoo = yahoofinance.get(ticker,
date_from=-5)
df_yahoo

Output

Transform dataframe

Params = orient
  • list: keys are column names, values are lists of column data
  • records: each row becomes a dictionary where key is column name and value is the data in the cell
dict_yahoo = df_yahoo.to_dict(orient="records")
dict_yahoo