【发布时间】:2020-11-17 22:28:34
【问题描述】:
将如下代码转换为能够接受任意数量的数据帧的最佳方法是什么?
def q_grab(df, df2, df3, q): #accepts three dataframes and a column name. Looks up column in all dataframes and combine to one
data = df[q], df2[q], df3[q]
headers = [q+"_1", q+"_2", q+"_3"]
data2 = pd.concat(data, axis = 1, keys=headers)
return data2
q = 'covid_condition'
data2 = q_grab(df, df2, df3, q) #If I run function pid_set first, it will create new df based on pID it looks like
【问题讨论】:
标签: python pandas definition