Search
 
SCRIPT & CODE EXAMPLE
 

SQL

pandas split column into multiple columns by delimiter

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

How to split a text column into two separate columns?

import pandas as pd 

df = pd.DataFrame(["STD, City    State",
"33, Kolkata    West Bengal",
"44, Chennai    Tamil Nadu",
"40, Hyderabad    Telengana",
"80, Bangalore    Karnataka"], columns=['row'])

out = pd.DataFrame(df.row.str.split(' ',2).tolist(),columns=['STD','City','State'])
out.drop(index=0,inplace=True)
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 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 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

PREVIOUS NEXT
Code Example
Sql :: *Action: Options are to resolve the compilation/authorization errors, disable the trigger, or drop the trigger. 
Sql :: fill up postgres db 
Sql :: redudancy in SQL 
Sql :: convert sqlalchemy.util._collections to list of string 
Sql :: current month mysql query 
Sql :: limiting query result using where in sql 
Sql :: How To Execute SQL Select Statements 
Sql :: codeigniter 3 get best-selling products 
Sql :: T-SQL MERGE with condition what is not matched? 
Sql :: IN from in sql 
Sql :: mysql order two columns 
Sql :: calcular edad en oracle 
Sql :: sql syntax chekcer 
Sql :: mysql exception output 
Sql :: http_user agent vers SQL 
Sql :: pl/pgsql declare variable 
Sql :: does laravel validate sql 
Sql :: transaction and commit trong sql server 
Sql :: HOW TO RETURN THE NUMBER OF LETTERS IN A cell in mysql 
Sql :: django mysqlclient connection string 
Sql :: java mysql swing example 
Sql :: MSSQL MAX VALOR 
Sql :: How is the default tablespace determined when creating a table? 
Sql :: sql update table one column 
Sql :: OFFSET consulta mysql 
Sql :: MySQL copy row with * 
Sql :: calculations on columns sql 
Sql :: sql to mongodb query converter 
Sql :: postgresql auto increment not working 
Sql :: capabilities of sql select statements 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =