Pandas how to apply multiple functions to dataframe

前端 未结 4 2197
粉色の甜心
粉色の甜心 2020-12-03 13:39

Is there a way to apply a list of functions to each column in a DataFrame like the DataFrameGroupBy.agg function does? I found an ugly way to do it like this:



        
4条回答
  •  旧时难觅i
    2020-12-03 14:15

    I tried to apply three functions into a column and it works

    #removing new line character
    rem_newline = lambda x : re.sub('\n',' ',x).strip()
    
    #character lower and removing spaces
    lower_strip = lambda x : x.lower().strip()
    
    df = df['users_name'].apply(lower_strip).apply(rem_newline).str.split('(',n=1,expand=True)
    

提交回复
热议问题