How to iterate over columns of pandas dataframe to run regression

后端 未结 8 1846
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条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-29 18:08

    You can index dataframe columns by the position using ix.

    df1.ix[:,1]
    

    This returns the first column for example. (0 would be the index)

    df1.ix[0,]
    

    This returns the first row.

    df1.ix[:,1]
    

    This would be the value at the intersection of row 0 and column 1:

    df1.ix[0,1]
    

    and so on. So you can enumerate() returns.keys(): and use the number to index the dataframe.

提交回复
热议问题