I have a list of dataframes in python.
sensors = [df_x, df_y, df_z]
df_x, df_y, df_z are dataframes
How to get name of the dataframe?
Ex: df_x, df_y, df_z
CodePudding user response:
df_x = ['df_x', (variable)]
df_y = ['df_x', (variable)]
df_z = ['df_x', (variable)]
sensors = [df_x[1], df_y[1], df_z[1]]
if you want to know variable name in string, df_x[0] is that one.
CodePudding user response:
If a variable starts with df_ is a dataframe to you. You can use this.
# If the values of the list are strings
sensors = ['df_x', 'df_y', 'df_z']
for i in sensors:
if i.startswith("df_"):
print(f"{i} is a dataframe")
print(f'{i} is not a dataframe')