Skip to content

Instantly share code, notes, and snippets.

@wrobstory
Created November 5, 2014 23:59
Show Gist options
  • Save wrobstory/60190cc3a052a58f5677 to your computer and use it in GitHub Desktop.
Save wrobstory/60190cc3a052a58f5677 to your computer and use it in GitHub Desktop.
Pandas string methods
In [1]: import pandas as pd
In [2]: df = pd.DataFrame({"col1": ["one.two", "three.four", "five.six"]})
In [3]: df['col_idx_0'] = df['col1'].str.split('.').str.get(0)
In [4]: df['col_idx_1'] = df['col1'].str.split('.').str.get(1)
In [5]: df
Out[5]:
col1 col_idx_0 col_idx_1
0 one.two one two
1 three.four three four
2 five.six five six
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment