I have a Pandas table and need to extract the stock code '00981', '00823' from text stored in a column. The code is in the (00000) format. The code would be located at different location in the text summary. Please advice.
News
1 example(00981)example example example。
2 example example example (00823)text text text
desired output:
Code column
981
823
s = TABLE['News'].str.find('(')
e = s + 5
c = TABLE['News'].str[s:e]
TABLE["Code"] = c
This works for me :
-to change the string into a number you can either leverage the
.astype()method orpd.to_numeric(df['stock_number'])