Given this DataFrame with columns: category
, Year
, and Profit
data = {'category':pd.Series(['A','A','A','A','A','A']),
'Year':pd.Series([1,1,3,3,3,4]),
'Profit':pd.Series([10,11,5,6,30,31])}
df = pd.DataFrame(data)
display(df)
how can I insert numbers creating a new column Numbering
by the following rule without manually enter the numbers one-by-one:
- Insert
0
for the correspondingYear < 3
. - Insert
1
at the first cell withYear >= 3
. - After that insert a geometric series with a common ratio of
0.5
for the correspondingYear >= 3
.
The desire output is displayed as follows: