Search code examples
pythonjupyter-notebooksklearn-pandas

Modifying a dataFrame in jupyter


i want to delete what after the : in this data (the password) and let just the emails

[emails] https://i.sstatic.net/dX9RB.png


Solution

  • You would be looking at apply.

    I think a solution like this:

    def remove_pw(x): #define your custom function
        y = x.split(":") #simple way to split on the colon
        return y[0] #return only the first part which is the email
    
    df = yourdata
    
    new_df = df['email'].apply(remove_pw)
    

    According to your image: ( I am assuming that what is shown is named df and is a valid pandas dataframe.)

    new_df = df['kobastal@yahoo.com:raskolnik'].apply(remove_pw)