Ask Your Question
3

In Python, can a string be utilized to retrieve a dataframe that has the same name as the string?

asked 2022-06-06 11:00:00 +0000

ladyg gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-11-15 05:00:00 +0000

lalupa gravatar image

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]
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-06-06 11:00:00 +0000

Seen: 21 times

Last updated: Nov 15 '21