How to iterate over columns of pandas dataframe to run regression

后端 未结 8 1848
Happy的楠姐
Happy的楠姐 2021-01-29 18:07

I\'m sure this is simple, but as a complete newbie to python, I\'m having trouble figuring out how to iterate over variables in a pandas dataframe and run a regress

8条回答
  •  猫巷女王i
    2021-01-29 18:08

    Based on the accepted answer, if an index corresponding to each column is also desired:

    for i, column in enumerate(df):
        print i, df[column]
    

    The above df[column] type is Series, which can simply be converted into numpy ndarrays:

    for i, column in enumerate(df):
        print i, np.asarray(df[column])
    

提交回复
热议问题