英文:
How can I create the name of a dataframe in a loop
问题
我想在循环中为我的数据框命名。
这个 没有解决我的问题,因为我想要更改我的数据框的名称,而不是列的名称。
所以,我想要做类似这样的事情:
dfx = [df123, df456]
names = [678, 01011]
for i, df in enumerate(dfx):
"df" + str(names[i]) = df.drop.loc[:, "column"]
这似乎很基础,但我不知道要查找什么。
一定有一些与正则表达式有关的事情,但我不知道从哪里查找或开始。
英文:
I want to name my dataframes in a loop.
This doesn't solve my problem in my understanding because I want to change my dataframes'n names not my columns's names.
So, I'd like to do something like this :
dfx = [df123, df456]
names = [678, 01011]
for i, df in enumerate(dfx):
"df" + str(names[i]) = df.drop.loc[:,"column"]
It seems basic but I don't know what to look for.
There must be something to do with regex but I don't know where to look or to start.
答案1
得分: 1
我不确定这可能需要什么目的,但我认为你可以将你的数据框添加到一个列表中,而不是使用许多具有不同名称的数据框,该列表可以包含你的不同数据框,或者也许一个字典可以帮助你为每个元素(数据框)命名。
英文:
I'm not sure for what purpose this could be needed, but I think you can instead of having many data frames with different names, you can add your data frames in a list, that list could have your different data frames, or maybe a Dict can help you to name each of your element(data frame).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论