1

How can I change data frame names in a list into the string with python?

list = [a,b,c,d]
# each element in the list is a dataframe
# I wanna change this list into
["a","b","c","d"]
  • Does this answer your question? [Getting the name of a variable as a string](https://stackoverflow.com/questions/18425225/getting-the-name-of-a-variable-as-a-string) – G. Anderson May 03 '21 at 15:54

1 Answers1

1

You can use this:

def get_df_name(df):
    return [x for x in globals() if globals()[x] is df][0]
l = [a,b,c]

l = list(map(get_df_name,l))
Nk03
  • 14,699
  • 2
  • 8
  • 22
  • While code-only answers might answer the question, you could significantly improve the quality of your answer by providing context for your code, a reason for why this code works, and some references to documentation for further reading. From [answer]: _"Brevity is acceptable, but fuller explanations are better."_ – Pranav Hosangadi May 03 '21 at 16:53