简体   繁体   English

在“for”循环中创建 dataframe,其中可以将 function 应用于它们

[英]Create dataframe in a “for” loop, in which a function can be applied to them

The first for loop seems to work.第一个 for 循环似乎有效。 However, when I move onto doing a groupby function on the next dataframe, something about the global variable in the for loop doesn't store the dataframe's correctly.但是,当我继续在下一个 dataframe 上执行 groupby function 时,for 循环中的全局变量无法正确存储数据帧。 Any help would be much appreciated.任何帮助将非常感激。 Thank you谢谢

chan_group = list(df_2017['Default Channel Grouping'].value_counts().index)
    

gbl = globals()

for i in chan_group:
    gbl['df_'+i] = df_2017[df_2017['Default Channel Grouping']==i]
    
g_chang_group = df_(Other), df_Aggregators, df_Direct, df_Display, df_Email, df_Email alerts, df_Newsletter, df_Organic Search, df_Paid Search, df_Partner referral, df_Referral, df_Retargeting, df_Social

for i in g_chan_group:
    x = i.groupby(['Month']).sum()

From @Nathan Furnal来自@Nathan Furnal

df_2017.groupby(["Default Channel Grouping", "Month"]).sum()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Boolean要使用For循环应用于Dataframe的函数 - Boolean Function to be applied to Dataframe with For Loop 我如何在应用的函数内部引用要对其应用函数的数据框 - How do I reference the dataframe to which a function is being applied inside the function applied 如何在数据帧中创建新列,该列将是另一列的函数,并且条件上比for循环快? - How to create a new column in dataframe, which will be a function of another column and conditionals faster than a for loop? 如何在数据框中创建新列,这将是其他列和条件函数的功能,而无需使用for循环遍历行? - How to create a new column in dataframe, which will be a function of other columns and conditionals without iteratng over the rows with a for loop? 我如何在两个列表和一个循环下的变量的帮助下创建 Dataframe - How can i create Dataframe with help of two list and a variable which is under a loop 编写一个复杂的 function 将应用于 DataFrame - Writing a complicated function that will by applied to a DataFrame 创建一个查找日期并将其拆分为pandas数据框列的函数 - Create a function that finds dates and split them into pandas dataframe columns 如何在没有 for 循环的情况下对每一列应用 function 从现有的创建一个新的 pandas DataFrame? - How can I create a new pandas DataFrame out of an existing one applying a function to every column without a for loop? Pandas Dataframe:我可以获取其他列值以及应用了哪个 group by 子句的列吗? - Pandas Dataframe: Can I fetch other column values along with the column on which group by clause has been applied? 功能未正确应用于熊猫数据框 - Function not being applied properly on a pandas dataframe
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM