ANOVA: DataFrame ha no Attribute alpha - 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: ANOVA: DataFrame ha no Attribute alpha (/thread-19771.html) |
ANOVA: DataFrame ha no Attribute alpha - Tese - Jul-13-2019 I'm a beginner in Python, but familiar with statistics. I'm trying to conduct Two Way ANOVA analysis in the use of Python examples from blogs. Specifically, I want to test two detergent brands, called Top and Alpha, in the use of cold and hot water. In the end, I can determine water temperature has in an effect on the effectiveness of detergents. But, unfortunately, I faced with errors in the beginning on in interaction plot construction and on the degree of freedom calculation as indicated below. I have enclosed below details, hypothetical data, codes, and errors. Please help me! import pandas as pd from statsmodels.formula.api import ols from statsmodels.stats.anova import anova_lm from statsmodels.graphics.factorplots import interaction_plot import matplotlib.pyplot as plt from scipy import stats data = pd.read_csv('C:\\Users\\Tesema\\Desktop\\PYTHON\\PYTHON3\\Deterent2.csv') print(data)
N = len(data.len) df_a = len(data.top.unique()) - 1 df_b = len(data.alpha.unique()) - 1 df_axb = df_a*df_b df_w = N - (len(data.top.unique())*len(data.alpha.unique()))
fig = interaction_plot(data.alpha, data.top, data.len, colors=['red','blue'], markers=['D','^'], ms=11)
RE: ANOVA: DataFrame ha no Attribute alpha - scidam - Jul-14-2019 You definitely need to clean up your data and restructure.
Instead of accessing to data-frame columns as attributes (e.g. df.top etc), consider using df['top'] , df['alpha'] . This is approach is more robust, especially in cases when column names collide with data-frame internal methods.You've got the error because your df hasn't a column named alpha (it hasn't a column named top too). .get_dummies should create these columns (but you need to clean up your data first).I think, your data have not been properly parsed (loaded). Consider passing a separator, e.g. sep=';' to the read_csv function.
RE: ANOVA: DataFrame ha no Attribute alpha - Tese - Jul-14-2019 (Jul-14-2019, 01:11 AM)scidam Wrote: You definitely need to clean up your data and restructure. Dear Scidam, thank you very much for respond. I will try your instruction, if possible can you give some clarification on Apply Method that you recommended in your above comment. Once again, thank you. RE: ANOVA: DataFrame ha no Attribute alpha - scidam - Jul-14-2019 The main issue here, I think, is missing sep=';' . You need to call read_csv with a parameter sep=';' , e.g.data = pd.read_csv('C:\\Users\\Tesema\\Desktop\\PYTHON\\PYTHON3\\Deterent2.csv', sep=';')If you do so, you will get a data frame, which has columns named Detergent_Brands , Cold , Hot without any semicolons.These columns will include values top and alpha (without any semicolumns too), so you won't need to apply any cleaning up at all. Try pass sep=';' and do df restructure as it is shown in #2.As far as .apply is concerned, you can read about this method in official docs.
RE: ANOVA: DataFrame ha no Attribute alpha - Tese - Jul-14-2019 (Jul-14-2019, 09:22 AM)scidam Wrote: The main issue here, I think, is missing Thank you very much for further comments, I will take your solution into consideration. Usually, I practice Python in weekends, I will try it in the coming weekend. |