close

[Solved] strptime() argument 1 must be str, not Series time series convert

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error strptime() argument 1 must be str, not Series time series convert in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How strptime() argument 1 must be str, not Series time series convert Error Occurs?

Today I get the following error strptime() argument 1 must be str, not Series time series convert in python.

How To Solve strptime() argument 1 must be str, not Series time series convert Error ?

  1. How To Solve strptime() argument 1 must be str, not Series time series convert Error ?

    To Solve strptime() argument 1 must be str, not Series time series convert Error You can solve this issue by using the .apply function in pandas to apply a function to every row of a dataframe.

  2. strptime() argument 1 must be str, not Series time series convert

    To Solve strptime() argument 1 must be str, not Series time series convert Error You can solve this issue by using the .apply function in pandas to apply a function to every row of a dataframe.

Solution 1

You can do it in two ways:

Method 1:

Here we pass a string to the function using map

list(map(lambda x: datetime.datetime.strptime(x,'%b %d, %Y').strftime('%m/%d/%Y'), old_df['oldDate']))

Method 2:

Here we pass a series

pd.to_datetime(old_df['oldDate'], format='%b %d, %Y')

Solution 2

old_df['oldDate'] will return the column containing the dates, which is a series.

You can solve this issue by using the .apply function in pandas to apply a function to every row of a dataframe. See here

def date_convert(date_to_convert):
     return datetime.datetime.strptime(date_to_convert, '%b %d, 
     %Y').strftime('%m/%d/%Y')

new_df['new_date'] = old_df['oldDate'].apply(date_convert)

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read