Skip to content
Advertisement

How to use the value in a variable as name to create a panda data frame?

In [182]: colname

Out[182]: ‘col1’

In [183]: x= ‘df_’ + colname

In [184]: x

Out[184]: ‘df_col1’

May I know how to create a new pandas data frame with x, such that the new data frame’s name would be df_col1

Advertisement

Answer

You can use the locals() function as given below,

JavaScript
Advertisement