Search code examples
pythonstringdataframeanovapatsy

How to string brackets within a dataframe column heading?


My excel sheet has Time(s) as a heading.

when I input it into one of my codes in python for two-way anova analysis like so:

 F1_para1 = 'ROI'
 F2_para2 = 'Drug'
 value = 'Time(s)'
   
 df['comb'] = df[F1_para1].map(str) + "+" + df[F2_para2].map(str) #group for pairwise comparison
 mod = ols(value+'~'+F1_para1+'+'+F2_para2+'+'+F1_para1+'*'+F2_para2, data = df).fit()
 aov = anova_lm(mod, type=2)

I get this error message

 PatsyError: Error evaluating factor: NameError: name 'Time' is not defined
    Time(s)~ROI+Drug+ROI*Drug
    ^^^^^^^

Was thinking it has something to do with (s) as it works fine with dataframe headings without brackets. Is there a way around this?

Current Troubleshooting attempts

  • I have tried doubling the brackets to troubleshoot it but I get this as an error:
PatsyError: Error evaluating factor: NameError: name 'Time' is not defined

Time((s))~ROI+Drug+ROI*Drug
^^^^^^^^^
  • I have also tried using str(Time(s))

Solution

  • Leaving this here in case someone needs help

    Use Q("Time(s)") to overcome the issue