How to use functions with pandas dataframe

后端 未结 2 2007
春和景丽
春和景丽 2021-01-25 15:41

How can I use function with pandas dataframe. For example:

a       | b
london  | uk
newyork | usa
berlin  | germany

df1 = df[[\'a\', \'b\']]

def doSomething(df         


        
2条回答
  •  失恋的感觉
    2021-01-25 16:16

    df1 = df[['a', 'b']]
    
    def doSomething(df):
    df2 = df['a']
    return df2
    
    df3 = df1.apply(doSomething, axis=1)
    df3 = pd.DataFrame(df3).rename(columns={0: 'a'})
    

提交回复
热议问题