Jul-30-2018, 05:44 AM
(This post was last modified: Jul-30-2018, 05:51 AM by saravanatn.)
I am new to Python and using python 2.7 version
I am trying to extract array column name using python.
Array column is mentioned below:
What I tried so far:
I want the output as
Actual output
.col,
.columnname1,
.columnname2,
.),
Expected output
col.columnname,
col.columnname1,
col.columnname2,
col.columnname3
Saravanan
I am trying to extract array column name using python.
Array column is mentioned below:
1 2 3 |
`col` array<struct< columnname:string,columnname1: int ,columnname2:decimal( 10 , 0 ), columnname3:decimal( 9 , 2 )>> I am spliting the column using split operator |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
import re str = input ( "enter any string:" ) fields = str .split( "," ) for x in fields: name = x.split( ":" ) seminame = name[ 0 ] + ',' firstname = seminame.find( '`' ) lastname = seminame.rfind( '`' ) fullname = seminame[(firstname + 1 ):lastname] replacename1 = fullname.replace( ')' , '') replacename2 = fullname.replace( '2' , '') replacename3 = fullname.replace( '9' , '') replacename4 = fullname.replace( '10' , '') replacename5 = fullname.replace( '0' , '') finalname = '.' + replacename5 print (finalname) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Input : '`col` array<struct< columnname:string,columnname1: int ,columnname2:decimal( 10 , 0 ), columnname3:decimal( 9 , 2 )>>' |
Actual output
.col,
.columnname1,
.columnname2,
.),
Expected output
col.columnname,
col.columnname1,
col.columnname2,
col.columnname3
Saravanan