I have a conditional csv file and I want to add an interval count for example from 1 to 6 to get something like this:
| A header | Another header | Another header |
|---|---|---|
| A | 2 | 1 |
| С | 7 | 2 |
| V | 4 | 3 |
| A | 1 | 4 |
| Q | 1 | 5 |
| V | 2 | 6 |
| N | 8 | 1 |
| A | 2 | 2 |
| L | 4 | 3 |
| A | 6 | 4 |
| S | 4 | 5 |
| F | 3 | 6 |
Is it possible to implement this using Pandas ?
>Solution :
Use vectorial code for efficiency, numpy is the perfect tool:
import numpy as np
N = 6
df['Another header'] = np.arange(len(df))%N+1
output:
A header Another header Another header
0 A 2 1
1 С 7 2
2 V 4 3
3 A 1 4
4 Q 1 5
5 V 2 6
6 N 8 1
7 A 2 2
8 L 4 3
9 A 6 4
10 S 4 5
11 F 3 6