mardi 1 novembre 2016

Pandas - Data Cleaning - Add New Column with if else statement for text values

I have a list of publisher that looks like this :

+--------------+
|  Site Name   |
+--------------+
| Radium One   |
| Euronews     |
| EUROSPORT    |
| WIRED        |
| RadiumOne    |
| Eurosport FR |
| Wired US     |
| Eurosport    |
| EuroNews     |
| Wired        |
+--------------+

I'd like to create the following result:

+--------------+----------------+
|  Site Name   | Publisher Name |
+--------------+----------------+
| Radium One   | RadiumOne      |
| Euronews     | Euronews       |
| EUROSPORT    | Eurosport      |
| WIRED        | Wired          |
| RadiumOne    | RadiumOne      |
| Eurosport FR | Eurosport      |
| Wired US     | Wired          |
| Eurosport    | Eurosport      |
| EuroNews     | Euronews       |
| Wired        | Wired          |
+--------------+----------------+

I would like to understand how I can replicate this code I use in Power Query :

search first 4 characters

if Text.Start([Site Name],4) = "WIRE" then "Wired" else

search last 3 characters

if Text.End([Site Name],3) = "One" then "RadiumOne" else

If no match is found, then add "Rest"

It does not have to be case sensitive.

Aucun commentaire:

Enregistrer un commentaire