Extract substring between two characters in pandas

10,178

As suggested in this answer https://stackoverflow.com/a/16842576/9754169 you can use the apply approach

your_column.apply(lambda st: st[st.find("[")+1:st.find("]")])
Share:
10,178

Related videos on Youtube

Shyama Sonti
Author by

Shyama Sonti

Updated on June 04, 2022

Comments

  • Shyama Sonti
    Shyama Sonti almost 2 years

    I have a column containing strings in this format:

    /* [MCCOOK 0     ] */,999990,'MCCOOK  0   '
    

    I want to extract the substring between [ and ] into another column. Please advise.

    • Yuca
      Yuca over 5 years
      what have you tried so far?