Skip to content
Advertisement

python to get substring of an excel cell with a condition

I’m trying to concatenate several csv files and create a ‘DATE_TIME’ column based on the specific column ‘NAME’. I apply an IF condition for extract the substring of DATE_TIME from NAME based on the appearance of a string ‘RE’.

Here’s my code:

JavaScript

My question is at the IF-ELSE statement. They return the same position of the substring, so that I get result below. This is not what I want, with the name ‘RE’ I still want to extract the date and time. What did I make a mistake for the code? Thank you.

enter image description here

Added my dataframe:

JavaScript

Advertisement

Answer

No need of IF statement. Split on – and concat the 2 last elements

EDIT

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