Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pandas split column into multiple columns by delimiter

df[['A', 'B']] = df['AB'].str.split(' ', 1, expand=True)
Comment

r separate column into multiple columns

df %>%
  separate(mainColumn,c('c1','c2'),'_',extra ='merge')
Comment

pandas split column into multiple columns

df.Name.str.split(expand=True,)
          0  1
0   Steve   Smith
1   Joe Nadal
2   Roger   Federer
Comment

split coumn of df into multiple dynamic columns

d = [pd.DataFrame(df[col].tolist()).add_prefix(col) for col in df.columns]
df = pd.concat(d, axis=1)

   id0  id1   id2  value0  value1  value2
0   10   10   NaN   apple  orange    None
1   15   67   NaN  banana  orange    None
2   12   34  45.0   apple  banana  orange
Comment

split a column into multiple columns

df[['A', 'B']] = df['AB'].str.split(' ', 1, expand=True)
df['A'], df['B'] = df['AB'].str.split('-', 1).str
Comment

pandas split cell into multiple columns

df[['A', 'B']] = df['AB'].str.split(' ', 1, expand=True)
Comment

split rows into multiple columns in pandas

df = pd.DataFrame(df.Raw_info.values.reshape(-1, 3), 
                   columns=['Function_name', 'prop1', 'prop2'])

print(df) 
  Function_name            prop1            prop2
0    Function_1  internal_prop_1  external_prop_1
1    Function_2  internal_prop_2  external_prop_2
2    Function_3  internal_prop_3  external_prop_3
Comment

Split Column with delimiter into multiple columns

DECLARE @tt TABLE(i INT IDENTITY,x VARCHAR(8000));
INSERT INTO @tt(x)VALUES('-9;-9;-1;-9;-9;-9;-9;-9;-1;-9;-9;-9;-9;-9;-9;-9;-9;-9;-1;-9;-9;-9;-9;-9;-9;-9;-9;-9;-1;-9;-1;-9;-9;-9;-1;-9;-9;-9;-9;-9;-9;-1;-1;-1;-1;-9;-1;-1;-9;-9;-9;-9;-1;-9;-1;-9;-9;-9;-1;-9;-1;-9;-1;-9;-9;-9;-9;-1;-9;-9;-1;-1;-9;-1;-1;0000;FFF8;-9;-9;-9;-1;-9;-1;-9;FFF6;-9;-1;-9;-1;-9;-1;-9;-9;-9;-9;-9;-9;-9;-9;-9;-9;-9;-9;-9;-9;-9;-9;-9;-9;-9;-9;-9;-9;-9;-9');

SELECT
    i,
    val1=n.v.value('/e[1]','VARCHAR(16)'),
    val2=n.v.value('/e[2]','VARCHAR(16)'),
    val3=n.v.value('/e[3]','VARCHAR(16)'),
    -- ... repeat for val4 .. val114
    val115=n.v.value('/e[115]','VARCHAR(16)')
FROM
    @tt
    CROSS APPLY (
        SELECT 
            CAST('<e>'+REPLACE(x,';','</e><e>')+'</e>' AS XML) AS itm
    ) AS i
    CROSS APPLY i.itm.nodes('/') AS n(v);
Comment

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

PREVIOUS NEXT
Code Example
Python :: group by pandas 
Python :: how to append to a list in python 
Python :: from django.core.management import execute_from_command_line ImportError: No module named django.core.management 
Python :: pytube get highest resolution 
Python :: how to use coordinates in python 
Python :: django save object in view 
Python :: how to configure a button in python tkinter 
Python :: pandas subplots 
Python :: dtype array 
Python :: import python file from another directory 
Python :: python clear stdout 
Python :: split coumn of df into multiple dynamic columns 
Python :: error: not well-formed (invalid token) 
Python :: read xml file in python 
Python :: How to Send WhatsApp API using python 
Python :: pd.concat in python 
Python :: python3 call parent constructor 
Python :: ValueError: `logits` and `labels` must have the same shape, received ((None, 10) vs (None, 1)). 
Python :: difference between set and list in python 
Python :: add image to pdf with python 
Python :: django on delete set default 
Python :: csv in python 
Python :: join in pathlib path 
Python :: transpose of a matrix in python numpy 
Python :: how to check if given primary key exists in django model 
Python :: groupby fillna 
Python :: DIVAB 
Python :: how to calculate log 10 in python 
Python :: [<matplotlib.lines.Line2D object at 0x7fee51155a90] 
Python :: how to append data in excel using python 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =