Split values in a column pandas

Code examples

4
0

how to use split in pandas

import pandas as pd 

# new data frame with split value columns 
data["Team"]= data["Team"].str.split(" ", n = 1, expand = True) 

# df display 
data 
3
0

pandas split by space

# importing pandas module  
import pandas as pd 

# new data frame with split value columns 
data["Team"]= data["Team"].str.split(" ", n = 1, expand = True) 

# df display 
data 
0
0

splitting column values in pandas

df[['A', 'B']] = df['AB'].str.split('@', 1, expand=True)
#'@' - Split at @
#1 = Axis 1 i.e on column level
0
0

Split column values

# make string version of original column, call it 'col'
df['col'] = df['col1'].astype(str)

# make the new columns using string indexing
df['col1'] = df['col'].str[0:2]
df['col2'] = df['col'].str[2:4]
df['col3'] = df['col'].str[4:6]

# get rid of the extra variable (if you want)
df.drop('col', axis=1, inplace=True)

In other languages

This page is in other languages

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................