Conversion to datettime

Viewed 26
table = soup.find_all('table')[0]
df = pd.read_html(str(table), flavor = 'bs4', header =[0])[0]
df.drop(['Unnamed: 0', 'Unnamed: 7'], axis = 1, inplace = True)
df.head()

I scraped the data with the above code and found the output:

    Grand Prix      Date        Winner              Car                    Laps Time
0   Bahrain         28 Mar 2021 Lewis Hamilton HAM  Mercedes                56  01:32:03.897
1   Emilia Romagna  18 Apr 2021 Max Verstappen VER  Red Bull Racing Honda   63  02:02:34.598

Now, I want to plot a bar plot with the above output with Winner as X Axis and Time as Y axis. However, time is an Object type. So, i used the following code to convert into Datetime:

df['Time'] = pd.to_datetime(df['Time'])

I get this error message when trying plot with the conversion to datetime:

ConversionError: Failed to convert value(s) to axis units: 'Time'

Kindly help me out with the possible solution or mistake I could rectify in my code so that I can reproduce the plot.

0 Answers
Related