Cannot use added variable for Anova

Viewed 14

Newbie data analyst here. I was trying to do ANOVA testing with Python based on Pokemon dataset (https://www.kaggle.com/abcsds/pokemon). What I was trying to do is assessing whether there is a difference between each generation with the total stats.

I added another variable 'Gen Str' which is to convert the Generation from int to str,

df['Gen Str'] = df[str('Generation')]

then used the following code to conduct the test:

model = ols('Total ~ Gen Str', data=df).fit()
anova_table = sm.stats.anova_lm(model, typ=2)
print(anova_table)

it returned the following error:

  File "<unknown>", line 1
    Gen Str
        ^
SyntaxError: invalid syntax

When I tried to do the ANOVA with Generation (original variable), it runs properly although I am concerned that the df returned is 1. Is it not possible to use ANOVA based on created variable? Thanks and hope to hear from you guys soon!

0 Answers
Related