Skip to content

Instantly share code, notes, and snippets.

@vikjam
Created July 21, 2021 19:00
Show Gist options
  • Save vikjam/546bc13aa2b2b5b37673f3c1e63b1d3c to your computer and use it in GitHub Desktop.
Save vikjam/546bc13aa2b2b5b37673f3c1e63b1d3c to your computer and use it in GitHub Desktop.
CSV to dict via pandas
import pandas as pd
from io import StringIO
params_df = pd.read_csv(
StringIO(
"parameter,value\ntheta,0.1\nbeta,0.5"
)
)
params_df
# parameter value
# 0 theta 0.1
# 1 beta 0.5
params_dict = params_df.set_index('parameter').to_dict('index')
theta = params_dict['theta']['value']
theta
# 0.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment