Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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
Comment

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)
Comment

PREVIOUS NEXT
Code Example
Python :: onedrive python upload 
Python :: roc auc score 
Python :: Python program to print positive numbers in a list 
Python :: insert row in dataframe pandas 
Python :: for loop 
Python :: use functions to resample pandas 
Python :: python readlines strip 
Python :: print on same line 
Python :: python logging level 
Python :: sys.maxsize() in python 
Python :: python choose function 
Python :: python list merger 
Python :: pickle python 
Python :: python list of size 
Python :: discordpy make all inputs lowercase 
Python :: remove toggle/pandaslux 
Python :: read data from gooogle cloud storage 
Python :: does tuple allow duplicate values in python 
Python :: python if index not out of range 
Python :: where to put capybara default wait time 
Python :: ValueError: Please provide a TPU Name to connect to. site:stackoverflow.com 
Python :: python convert xml to dictionary 
Python :: fetch firestore indexes 
Python :: Pillow opencv convert RGB to BRG or RGB to BRG 
Python :: argsort in descending order numpy 
Python :: python arabic web scraping 
Python :: pythonhashseed 
Python :: how to uninstall python-dotenv 
Python :: selenium screenshot python user agent 
Python :: dependency inversion 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =