0

I wrote the command bellow :

pd.DataFrame(df.groupby(['CHAUFFEUR','comportement de conduit'])['comportement de conduit'].count())

I get the dataframe bellow :

CHAUFFEUR comportement de conduit comportement de conduit
ABBAD DJELLOUL bad driving behaviour(reduce your acceleration) 1
ABBOU ABD EL KADER bad driving behaviour 5
bad driving behaviour(reduce your acceleration,increase your speed) 14
... ... ...
ZIANE ABDELKADER good driving behaviour(try to reduce acceleration) 18
normal driving behaviour 24
very good driving behaviour 4

Now I need to select for each CHAUFFEUR all numbers of his comportement de conduit for example for the second CHAUUFEUR named ABBOU ABD EL KADER i need to select only :

bad driving behaviour 5
bad driving behaviour(reduce your acceleration) 41

So how can I do it please

Tae In Kim
  • 194
  • 2
  • 13
miss-chl
  • 19
  • 1
  • 6

2 Answers2

0

fill the null values with forward fill to fill in the blank values.

make the empty cell as np.nan

df['CHAUFFEUR'] = df['CHAUFFEUR'].str.strip().replace("", np.nan)
df['CHAUFFEUR'] = df.fillna(method='ffill')

OR

df['name'] = df['name'].str.strip().replace("", np.nan).fillna(method='ffill')
Naveed
  • 11,495
  • 2
  • 14
  • 21
  • @miss-chl, is that what you were looking for? did it addressed the question? – Naveed Jun 16 '22 at 08:39
  • not really what i need exactly is to count for every driver (**CHAUFFEUR**) the number of different classe béhavior – miss-chl Jun 17 '22 at 17:41
0

If you use str.contains can find the answer

df = df[df['comportement de conduit'].str.contains('bad driving behaviour')]

This will show you a row for the included string.

I hope you solve it well.

Tae In Kim
  • 194
  • 2
  • 13