0

I am working on a data cleaning project using Python 3 and a panda's dataframe. As a specific example: one of the changes I want to make is to a certain section of the dataframe that includes dates in a different format from the remained of the dataframe. I am able to make the changes I want to the format of the dates using a for loop, but I do not now how to insert these dates back into the dataframe.

Below is the code I have for parsing and rearranging the current datetime format (m/d/yy hh:mm)to the desired datetime format (yyyy/mm/dd hh:mm):

wrongDateFormat = df.iloc[807:1029]

for b in wrongDateFormat['datetime']:
        date = b.split()[0]
        time = b.split()[1]
        date = date.split('/')
        year = date[2]
        year = "20" + year
        month = date[0]
        if int(month) < 10:
            month = '0' + str(month)
        day = date[1]
        if int(day) < 10:
            day = '0' + str(day)

        b = year + '/' + month + '/' + day + ' ' + time
        print(b)

This code outputs:

2006/08/24 6:36
2006/08/23 11:59
2006/08/22 7:55
2006/08/21 2:25
2006/08/20 9:15
2006/08/19 8:16

Does anyone know how I can update the original dataframe with these new dates? Thanks in advance. It seems like the .set_value method used in this similar resolved question has depreciated since version 0.21.0.

4

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.