how to add column on panda based on another column partial string
<p>I´m quite new with python and pandas. I´m trying to add a new column to a data frame (group column) with values based on a partial string in another column (user column). Users are coded like this: AA1, AA2, BB1, BB2 and so on. What I want is the group column to have a 'AA' value for all the AA users. After looking for a way to do this, I came up with the following line:</p>

<pre><code>df['group'] = ['AA' if x x.startswith('AA') else 'other' for x in df['user']]
</code></pre>

<p>Well,it does´t work: 
1) I get invalid syntax and line too long error
2) However, it does work if I change x.startswith('AA') for x == 'AA1', so is it something with the startswith part?
3) I don´t know how to add the 'BB' if x x.starts with('BB') in the same line, or should I write a line for each category of user?  Thank you so much</p>