Skip to content

Instantly share code, notes, and snippets.

@rajarshi
Created November 17, 2021 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rajarshi/e7427d494ef4cc17294cc419fa7352c4 to your computer and use it in GitHub Desktop.
Save rajarshi/e7427d494ef4cc17294cc419fa7352c4 to your computer and use it in GitHub Desktop.
stripping chars in pandas
import pandas as pd
if __name__ == '__main__':
d = {'col1': [1, 2, 3],
'col2': ['{abc defg', '{xyz pqr}', '{nan, foo}']}
df = pd.DataFrame(d)
print(df)
df['col3'] = df['col2'].str.strip("{|}").astype('str')
print(df)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment