'how can i get mean value of str type in a dataframe in Pandas

I have a DataFrame from pandas:

i want to get a mean value of "stop_duration" for each "violation_raw". How can i do it if column "stop_duration" is object type

df = enter code herepd.read_csv('police.csv', parse_dates=['stop_date'])
df[['stop_date', 'violation_raw','stop_duration']]

My table:

the table



Solution 1:[1]

Use to_datetime function to convert object to datetime. Also specifying a format to match your data.

import pandas as pd    
df["column"] = pd.to_datetime(df["column"], format="%M-%S Min")

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ndnag