0
$\begingroup$

I have the premiered column where I want to remove the year and only keep the season. Example: "winter 2021" to become "winter" .

enter image description here

$\endgroup$
0
$\begingroup$

Try something like this Regular expression to_replace

df = pd.DataFrame({'A': ['bat', 'foo', 'bait'], 'B': ['abc', 'bar', 'xyz']}) df.replace(to_replace=r'^ba.$', value='new', regex=True) ... A B 0 new abc 1 foo new 2 bait xyz

In your case it will be: df.replace(to_replace=r'^Fa.$', value='Fall', regex=True) ... ...

For future, I suggest refer here about regular expressions: https://docs.python.org/3/library/re.html

Note: ^ (Caret.) Matches the start of the string, and in MULTILINE mode also matches immediately after each newline.

$\endgroup$
0
$\begingroup$

Try

df['Column'] = df['Column'].str.replace('\d+', '')

this will remove all digits in the column

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.