My data is in the form given below
Number
ABCD0001
ABCD0002
ABCD0003
GHIJ768O
GHIJ7681
GHIJ7682
SEDFTH1
SEDFTH2
SEDFTH3
I want to split this data into multiple colunms using postgreSQl/python script?
The output data should be like
Number1 Number2 Number3
ABCD0001 GHIJ7680 SEDFTH1
ABCD0002 GHIJ7681 SEDFTH2
Can I do this using an postgreSQl query or via a python script?
This is just a quick solution to your problem, i'm still learning python myself. So this code snippet could probaly be optimized alot. But it solves your problem.
import pandas as pd
number = ['ABCD0001','ABCD0002','ABCD0003','GHIJ768O','GHIJ7681','GHIJ7682','SEDFTH1','SEDFTH2','SEDFTH3']
def find_letters(list_of_str):
abc_arr = []
ghi_arr = []
sed_arr = []
for i in range(len(list_of_str)):
text = number[i]
if text.__contains__('ABC'):
abc_arr.append(text)
if text.__contains__('GHI'):
ghi_arr.append(text)
if text.__contains__('SED'):
sed_arr.append(text)
df = pd.DataFrame({'ABC':abc_arr, 'GHI':ghi_arr, 'SED':sed_arr})
return df
This code give this output. Screenshot Of Output
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.