Home > Enterprise >  Pyhton pandas for manipulate text & inconsistent data
Pyhton pandas for manipulate text & inconsistent data

Time:09-16

how i take specific text from one column in python pandas but inconsistent format for example like this

Area | Owners

Bali Island: 4600 | John

Java Island:7200 | Van Hour

Hallo Island : 2400| Petra

and the format would be like this

Area | Owners | Area Number

Bali Island: 4600 | John | 4600

Java Island:7200 | Van Hour | 7200

Hallo Island : 2400| Petra | 2400

CodePudding user response:

You could use str.extract:

df['Area Number'] = df['Area'].str.extract('(\d )$')

output:

                  Area    Owners Area Number
0    Bali Island: 4600      John        4600
1     Java Island:7200  Van Hour        7200
2  Hallo Island : 2400     Petra        2400
  • Related