-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,072
  • 3
  • 15
  • 38
Nabih Bawazir
  • 3,867
  • 4
  • 20
  • 43

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
  • 3,867
  • 4
  • 20
  • 43
Mohit Motwani
  • 4,072
  • 3
  • 15
  • 38
1

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

df['target'] = ''
df['target'].iloc[3] = 'bad'
Nabih Bawazir
  • 3,867
  • 4
  • 20
  • 43
gyoza
  • 1,982
  • 2
  • 10
  • 18