Python Forum
Insert missing data in a dataframe
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Insert missing data in a dataframe
#2
Perhaps I am not the right person to answer your question. Perhaps better tools can be found in pandas, but if everything else fails, you could solve it with elementary python. To calculate with time you need the datetime module with datetime and timedelta. Datetime stores a timestamp in an object. With timedelta you can calculate. So you can make a function to convert a datetime string to a datetimestring two minutes later. Like this.
from datetime import datetime, timedelta

dtformat = "%Y-%m-%d %H:%M:%S"
twominutes = timedelta(minutes=2)

def computenexttime(dtstring: str) -> str:
    """ Input is a string in datetime format, output is the next time in string format. """
    # Make datetime object.
    datetimeobj = datetime.strptime(dtstring, dtformat)
    # Compute next datetime.
    nextdtobj = datetimeobj + twominutes
    # Return next datetime as a string.
    return nextdtobj.strftime(dtformat)
With this function you can check if a line is two minutes later than the previous. Is this enough to handle the problem? Please show us what you made of it.
Reply


Messages In This Thread
Insert missing data in a dataframe - by amdi40 - Jan-16-2022, 02:15 PM
RE: Insert missing data in a dataframe - by ibreeden - Jan-17-2022, 09:59 AM
RE: Insert missing data in a dataframe - by amdi40 - Jan-17-2022, 02:40 PM
RE: Insert missing data in a dataframe - by amdi40 - Jan-19-2022, 07:47 AM
RE: Insert missing data in a dataframe - by amdi40 - Jan-19-2022, 08:55 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020