LoginSignup
0
1

More than 3 years have passed since last update.

dataframeでの関数適用のサンプルです。

Posted at

テストデータ

import pandas as pd

df=pd.DataFrame({"A":[1,2,3],"B":[10,20,30]})
print(df.to_markdown())
A B
0 1 10
1 2 20
2 3 30

サンプルソース

def fnc(dt):
    return dt["A"]+dt["B"]

df["C"]=df.apply(lambda dt :  fnc(dt) ,axis=1  ) 
print(df.to_markdown())

結果

A B C
0 1 10 11
1 2 20 22
2 3 30 33
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1