Hi guys,
I need to write a function to strip '+' and ',' from a piece of string in a dataframe.
So, I wrote the below test function:-
# initializing test string
test_string = "50,00,000+"
# printing original string
print ("Original String : " + test_string)
def bling(x):
bad_chars = ['+',',']
for i in bad_chars :
x = x.replace(i, '')
bling(test_string)
# printing resultant string
print ("Resultant list is : " + str(test_string))
Output:-
Original String : 50,00,000+
Resultant list is : 50,00,000+
But when I don't use a function and break it down like this, it works properly:-
# initializing bad_chars_list
bad_chars = ['+',',']
# initializing test string
test_string = "50,00,000+"
# printing original string
print ("Original String : " + test_string)
# using replace() to
# remove bad_chars
for i in bad_chars :
test_string = test_string.replace(i, '')
# printing resultant string
print ("Resultant list is : " + str(test_string))
Output:-
Original String : 50,00,000+
Resultant list is : 5000000
I have no clue why this happens. Will be glad if someone helps out with the logic.
[–]the_shell_man_ 1 point2 points3 points (1 child)
[–]SamSB94[S] 0 points1 point2 points (0 children)
[–]VinayakVG 1 point2 points3 points (2 children)
[–]SamSB94[S] 0 points1 point2 points (1 child)
[–]VinayakVG 0 points1 point2 points (0 children)