The first if function is to remove the space in different numbers inside an excel sheet [data.sales_mm_mno1=='50 000','sales_mm_mno1'] = 50000
The second if function to choose the first number of phone among the two numbers [data.phone_number=='79394509/74793733','phone_number'] = 79394509
CodePudding user response:
You can use str.split
for both of these.
For the first example, split
on whitespace and then join
with an empty string:
>>> sales_mm_mno1 = "50 000"
>>> ''.join(sales_mm_mno1.split())
'50000'
For the second example, split
on "/"
and then take the first element with [0]
:
>>> phone_number = '79394509/74793733'
>>> phone_number.split("/")[0]
'79394509'
CodePudding user response:
This is the simplest technique to achieve your aim.
phone_number = '79394509/74793733' phone_number = phone_number.split("/") phone_number = phone_number[0] phone_number = int(phone_number) print(phone_number)
Output :
79394509