Linked Questions

Popular Questions

How to remove certain characters from a dataframe in python?

Asked by At

I have a dataframe that looks like this. Some rows contain a number..

For example, df['Origin'][0] has 1, and df['Name'][7] has 3. I need to remove all of this numbers, and I cannot find a way. Could you help me? Thank you.

        Name              Origin   
0   Angel cake    United Kingdom 1
1   Angel food cake   United States
2   Apple cake    Germany
3   Applesauce cake   Early colonial times in the New England Coloni...
4   Aranygaluska      HungaryRomania
5   Avocado cake      None
6   Babka   Poland    None
7   Ballokume 3   Albania

I've tried with df_cakes.replace({"1":''}, regex=True) but doesn't work.

Therefore, the dataframe should look like this:

        Name              Origin   
0   Angel cake    United Kingdom 
1   Angel food cake   United States
2   Apple cake    Germany
3   Applesauce cake   Early colonial times in the New England Coloni...
4   Aranygaluska      HungaryRomania
5   Avocado cake      None
6   Babka   Poland    None
7   Ballokume     Albania

Related Questions