extract data from date range (time & date format)

Brendon

I have a date set for a couple of years and I am trying to extract data from a specific range and time, but I cannot get it to work with Pandas. I am sure there is something wrong with the date & time format, but oddly I can get hourly averages but cannot extract a date & time range.

This is the code, but it never return any data, I know it there is data in that time period. I think the date & time format is correct, but not sure why it does not work. Any help would be highly appreciated

Code

import pandas as pd

import numpy as np

df = pd.DataFrame([['2018-01-01 16:00:00+00:00', 2], ['2018-01- 
01 17:00:00+00:00', 3], ['2018-01-01 18:00:00+00:00', 6]['2018- 
01-01 19:00:00+00:00', 9]], columns=['time', 'data'])

print(df.head)

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

df2018 = df.loc['2018-01-01 16:30:00':'2018-01-01 18:00:00']

print(df2018.head)
Language Tech

Is the time column your index? if not, make it your index:

pd.set_index(df['time'])

Then:

df["2018-10-02":"2018-10-03"] # slicing a date period

df.loc[(df['time'] > start_date) & (df['time'] <= end_date )] 

Este artigo é coletado da Internet.

Se houver alguma infração, entre em [email protected] Delete.

editar em
0

deixe-me dizer algumas palavras

0comentários
loginDepois de participar da revisão

Artigos relacionados

Extracting time from a date/time format

How to extract time from date string in javascript?

date time format value -

Eliminate time value from date field and change the format while fetching data from database

Output data by date range

Extract date from varchar

Extract date out of cell with date and time

How to extract data between a date range which has only start and end date values in the table?

Split date range with time by day

Extract only date from datetime for calculating total time in PHP

How to extract date time from sql and bind it to datetimePicker

Importing multiple csv files at the same time want the date data converted into (date and time) format in R

Machine date time format overrides code date time format

Changing Windows Time and Date Format

How to give date time a format?

Extract "Mon-YY" from a date as a Date

Subsetting data table by date range

Extract data and sort them by date

converting JSON time and date format and location format

Convert GMT date format to only time format

Get weeks from date range

Regex expression to extract From & To Date?

how to convert date format range in php

How to convert data frame headers from excel values to date format

How to convert date time format to date and time object?

How to extract date and time in a given string in Javascript

Unable to successfully extract timestamp to date and time in pyspark

Sending data from cakephp automatically using date and time

Calculating the date from a series of consecutive time data (R)