首页 > 解决方案 > 如何使用 python 将列表中的数据框名称更改为字符串?

问题描述

如何使用 python 将列表中的数据框名称更改为字符串?

list = [a,b,c,d]
# each element in the list is a dataframe
# I wanna change this list into
["a","b","c","d"]

标签: pythonstringlistdataframe

解决方案


你可以使用这个:

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))

推荐阅读