Skip to content
Advertisement

Rename a row with X unknown characters

If I have the following dataframe:

ID other
219218 34
823#32 47
unknown 42
8#3#32 32
1#3#5# 97
6#3### 27

I want to obtain the following result:

ID other
219218 34
823#32 47
unknown 42
8#3#32 32
unknown 97
unknown 27

I am using the following code which works.

JavaScript

Is there a way to make it more optimal, bearing in mind that I am going to apply the code to a dataframe of more than 60,000 rows?

Thank you for your help.

Advertisement

Answer

For an efficient solution, use vectorial methods and assign with loc:

JavaScript

output:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement