如何在循环中创建数据框的名称

huangapple go评论67阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年5月24日 21:57:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/76324328.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定