0
0

More than 1 year has passed since last update.

特定条件の項目に対して列と値を追加

Posted at

目的

特定条件の項目に対して列と値を追加

コード

import pandas as pd

input_file = pd.read_csv('test.csv')
print(input_file)
input_file.loc[(input_file['name'] == 'Akebono') & (input_file['Weight'] == 90), 'Age'] = '31'
print(input_file)

出力結果

      name  Height  Weight
0  Akebono     170      65
1    Shota     171      59
2  Akebono     169      90
3   Yamato     175      50
      name  Height  Weight  Age
0  Akebono     170      65  NaN
1    Shota     171      59  NaN
2  Akebono     169      90   31
3   Yamato     175      50  NaN
0
0
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
0