Consider this dataframe:
pd.DataFrame(['A(3)BC(1)', 'A(2)BC(5)', 'A(1)BC(3)', 'A(2)BC(5)', 'A(4)BC(2)'], columns=['Column1'])
Column1
0 A(3)BC(1)
1 A(2)BC(5)
2 A(1)BC(3)
3 A(2)BC(5)
4 A(4)BC(2)
Is there a way to count the number of times A has a number higher than (3) without iterating through every line of the dataframe?
>Solution :
Let’s try
out = df['Column1'].str.extract('A\((\d+)\)')[0].astype(int).gt(3).sum()
print(out)
1