'How to handle variable name with brackets in Numpy for where function?

I am new with Numpy. I am trying to play around with dummy data and I wanted to name my variable T(s).

> #turning normal arrays into dataframes score_df_A = pd.DataFrame({'T(s)':score_array_A,'Domains':'2'})

But when I use this variable in where function like below:

> score_data = score_data.assign(Req = np.where(score_data.T(s) %3 > 1,
> "5","10"))

It gives me error: NameError: name 's' is not defined

While using where functions how can we deal with variable name having brackets like ()?

Thanks.



Solution 1:[1]

Rules for creating variables in Python:

  • A variable name must start with a letter or the underscore character.

  • A variable name cannot start with a number.

  • A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ).

https://www.geeksforgeeks.org/python-variables/

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 matszwecja