So, I am quite new to python, and this my first ever stack overflow post.
So I have a column in data frame that contains actions in poker hand abbreviated as letters.
pdb_RED.PRFLOP_A.unique()
array(['BrA', 'Brf', 'Bk', 'f', 'Bc', 'r', 'Bf', 'c', 'B', 'Br', 'cc',
'Bcf', 'Bcc', 'BcrA', 'Brc', 'BQ', 'Brr', 'rf', 'rc', 'BrQ', 'BcA',
'cr', 'cf', 'Q', 'fQ', 'BKQ', 'rr', 'BrcA', 'rrc', 'Bcr', 'BcQ',
'BA', 'rQ', 'BfQ', 'rA', 'KQ', 'rrA'], dtype=object)
I want to create a new column in my data frame, that contains dummy variable for 1, if the expression is matched in a column, and 0 for everything else. Expression:
A1_agro=pdb_RED['PRFLOP_A'].str.contains('[bBrA]$', regex=True)
It returns a tuple with True/False values. (So 1 for True , 0 for False i need) I proceed by creating an empty column in my original data frame, and later follow with an attempt with my limited knowledge. I hope someone can give my directions, because it returns 'tuple' object does not support item assignment' error.
pdb_RED['PRFLOP_agro']=np.nan
for row in pdb_RED.iterrows():
if A1_agro[1]==True:
row['PRFLOP_agro']=1
else:
row['PRFLOP_agro']=0