poisson regression - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: poisson regression (/thread-26185.html) |
poisson regression - d8a988 - Apr-23-2020 I am working with poisson regression with pandas and I have a question about this specific command poisson(y,x). with y,x being respectively the dependent, independent variables. the following code takes two columns from an excel file and works properly import pandas as pd from statsmodels.formula.api import poisson from statsmodels.formula.api import negativebinomial data = pd.read_csv(r'file.csv') varcomp = 'y ~ x' model_1 = poisson(varcomp, data).fit() print( model_1.summary()) but now I want x and y to be two rows instead of columns, but I am a bit lost and don't know how to proceed. I have tried to convert those two columns into lists, since I will be able to do the same with rows, but once I implement them into the poissoncommand, I get an error. Thank you in advance. x_list=data['x'].tolist() y_list=data['y'].tolist() model_1 = poisson('y_list ~ x_list', data).fit() print( model_1.summary())
RE: poisson regression - jefsummers - Apr-23-2020 Did you try transposing the dataframe? tdata = data.transpose() RE: poisson regression - d8a988 - Apr-23-2020 I was certainly not aware of that option, and thanks for letting me know. However, if possible, I would like to stick to lists, since it gives me more freedom to do what I need to do, for instance in some cases, I have to sum the numbers from different cells before starting to work with them, and I am not sure how else to do it. Any ideas? |