Python(String): Using a string saved in a DataFrame cell as a pandas Formula

Viewed 105

I have a dataframe InputDF shown below. It has only one column Col1 (the 0'th column), whose values are all string:

enter image description here

I am trying to use the values in column 0 as a formula in pandas (mentioned below) I have another empty data frame DF2where I try the following to insert data:

DF2 = InputDF.loc[0,0] 

...this comes to DF2["column1"] = 'p_input[Order No]'

I need this to be DF2["column1"] = p_input[Order No] so that I can save data available in "Order No" column of p_input dataframe in "columns1" column of "DF2" dataframe

[Note: p_input is another dataframe, due to some issues these assumptions can not change]

1 Answers

eval is your friend: DF2 = eval(p_input[Line Of Business])

Related