0

i want to add specific column that related to other column in dataframe

this is my code:

import pandas as pd
import numpy as np

df = pd.DataFrame(
    data={'index': ['1','2','3','4','5','6','7','8','9','10'], 
    'charac' : ['A','A','A','A','A','A','A','B','B','B']})

When it's the same in 'charac', it goes on continuously. but it's different in 'charac', it starts again

like this 'add_col' = [1,2,3,4,5,6,7,1,2,3]

i think it can be work with 'for' but i don't know how to do .... could you tell me the answer ..?

DOOM
  • 1,170
  • 6
  • 20

0 Answers0