Created
November 17, 2021 15:18
-
-
Save rajarshi/e7427d494ef4cc17294cc419fa7352c4 to your computer and use it in GitHub Desktop.
stripping chars in pandas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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