I have a reoccurring task in the code I am developing where I have a list of functions such as:
df1 = pd.DataFrame(data=[1,2,3], columns=['a', 'b', 'c'])
df2 = pd.DataFrame(data=[4,5,6], columns=['a', 'b', 'c'])
df3 = pd.DataFrame(data=[9,8,7], columns=['a', 'b', 'c'])
df_list = [df1, df2, df3]
And I want to apply a function (or filter) each one the same way. I am currently using a for loop to perform this task such as:
new_df_list = []
for df in df_list:
new_df_list.append(df.apply(some_func))
But I was wondering if there was a more elegant way that I can implement?
Thanks for any thoughts in advance!
question from:
https://stackoverflow.com/questions/65599439/apply-a-function-to-a-list-of-pandas-dfs 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…