1 | initial version |
No, a string cannot be directly used to retrieve a dataframe that has the same name as the string in Python. However, it is possible to use a dictionary or a global variable to store the dataframes with their respective names as keys and then use the string as a key to retrieve the desired dataframe.
For example:
# Creating a dictionary to store dataframes
dfs = {"df1": df1, "df2": df2}
# Retrieving a dataframe using a string variable
df_name = "df1"
df = dfs[df_name]