I'm trying to create a series of variables based on an existing df column. Example :
import pandas as pd
dates = {'expiries': ['10','11','13','14']}
expiries = pd.DataFrame(dates)
expiries
I then want to create a new variable (var1 through var4) giving it the value from each row. I know I can get it by going:
var1 = expiries['expiries'].iloc[0]
var2 = expiries['expiries'].iloc[1]
var3 = expiries['expiries'].iloc[2]
var4 = expiries['expiries'].iloc[3]
but in reality my df is a variable length and I need a variable per row not a pre determined (hardcoded) number of variables.
forloop?expiries['expiries'].to_dict()and refer the keys later if really required, since creating variables from a loop isnt a great idea. ref: stackoverflow.com/questions/1373164/…