-3

Here's my data

     customer_id       feature_1        feature_2      feature_3
0    1                 78               73             63
1    2                 79               71             66
2    2                 82               76             69
3    3                 43               32             53
4    3                 63               42             54

I want to label the dataframe one by one. For example, for index = 3, target is Bad

     customer_id       feature_1        feature_2      feature_3     target
0    1                 78               73             63
1    2                 79               71             66
2    2                 82               76             69
3    3                 43               32             53            bad
4    3                 63               42             54

Basically, I do the process of pulling out one by one with my anotation specialsit

Best regards

Mohit Motwani
  • 4,662
  • 3
  • 17
  • 45
Nabih Bawazir
  • 6,381
  • 7
  • 37
  • 70

2 Answers2

2

Use the set_value function

syntax format is: `DataFrame.set_value(index, col, value, takeable=False)[source]`

So for your question the answer would be

df.set_value(3, 'target', 'bad')
Nabih Bawazir
  • 6,381
  • 7
  • 37
  • 70
Mohit Motwani
  • 4,662
  • 3
  • 17
  • 45
1

Alternatively, you can add empty column first, then fill a cell with desired value

df['target'] = ''
df['target'].iloc[3] = 'bad'
Nabih Bawazir
  • 6,381
  • 7
  • 37
  • 70
gyoza
  • 2,112
  • 2
  • 12
  • 18