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

Input

Import libraries

1
from naas_drivers import yahoofinance
Copied!

Input parameters

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

Model

Get dataframe from Yahoo Finance

1
df_yahoo = yahoofinance.get(ticker,
2
date_from=-5)
3
df_yahoo
Copied!

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
1
dict_yahoo = df_yahoo.to_dict(orient="records")
2
dict_yahoo
Copied!
Copy link
Edit on GitHub