Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

df columns has multiple comma separested values split into columns generate column name auto

import pandas as pd
import numpy as np

df = pd.DataFrame(
    {'CustNum': [32363, 31316],
     'CustomerName': ['McCartney, Paul', 'Lennon, John'],
     'ItemQty': [3, 25],
     'Item': ['F04', 'F01'],
     'Seatblocks': ['test', 'test2,test3,test4'],
     'ItemExt': [60, 360]
    }
)
print(df)

df = df.join(df['Seatblocks'].str.split(',', expand=True).add_prefix('Seatblocks'))
print(df)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #df #columns #multiple #comma #separested #values #split #columns #generate #column #auto
ADD COMMENT
Topic
Name
9+2 =