Identifying and removing invalid time steps in a pandas time seriesRemove rows with duplicate indices (Pandas DataFrame and TimeSeries)Selecting a row of pandas series/dataframe by integer indexCombining two Series into a DataFrame in pandasPretty-print an entire Pandas Series / DataFramePandas conditional creation of a series/dataframe columnTime-series boxplot in pandasTime series Analysis in Rhow to sort from greatest to least in a .csv file in pythonread data table from .txt file and parse it to variablesorting instance of dict_items/sorting dictionary by value

What does it mean to describe someone as a butt steak?

Watching something be written to a file live with tail

Python: next in for loop

What do the dots in this tr command do: tr .............A-Z A-ZA-Z <<< "JVPQBOV" (with 13 dots)

Font hinting is lost in Chrome-like browsers (for some languages )

Why "Having chlorophyll without photosynthesis is actually very dangerous" and "like living with a bomb"?

How do I create uniquely male characters?

Do VLANs within a subnet need to have their own subnet for router on a stick?

How to find program name(s) of an installed package?

Is it legal for company to use my work email to pretend I still work there?

Email Account under attack (really) - anything I can do?

What's the point of deactivating Num Lock on login screens?

Test if tikzmark exists on same page

What are the differences between the usage of 'it' and 'they'?

What does "Puller Prush Person" mean?

Adding span tags within wp_list_pages list items

Risk of getting Chronic Wasting Disease (CWD) in the United States?

What typically incentivizes a professor to change jobs to a lower ranking university?

Why doesn't H₄O²⁺ exist?

Why can't I see bouncing of a switch on an oscilloscope?

Why does Kotter return in Welcome Back Kotter?

Why, historically, did Gödel think CH was false?

Is a tag line useful on a cover?

LaTeX closing $ signs makes cursor jump



Identifying and removing invalid time steps in a pandas time series


Remove rows with duplicate indices (Pandas DataFrame and TimeSeries)Selecting a row of pandas series/dataframe by integer indexCombining two Series into a DataFrame in pandasPretty-print an entire Pandas Series / DataFramePandas conditional creation of a series/dataframe columnTime-series boxplot in pandasTime series Analysis in Rhow to sort from greatest to least in a .csv file in pythonread data table from .txt file and parse it to variablesorting instance of dict_items/sorting dictionary by value






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I looked for an answer for this for a while but haven't been able to find anything, so forgive me if this question has been asked before...



I have some 6-hourly timeseries data future of future temperature projections for the years 2031-2050. Upon looking at the data, I notice that there is some faulty timedeltas in the dataset starting at future.iloc[234]:



future.iloc[220:281]

time Temp
220 2031-03-28 00:00:00 68.276657
221 2031-03-28 06:00:00 68.270706
222 2031-03-28 12:00:00 68.264748
223 2031-03-28 18:00:00 68.258781
224 2031-03-29 00:00:00 68.252808
225 2031-03-29 06:00:00 68.246849
226 2031-03-29 12:00:00 68.240883
227 2031-03-29 18:00:00 68.234909
228 2031-03-30 00:00:00 68.228943
229 2031-03-30 06:00:00 68.222984
230 2031-03-30 12:00:00 68.217010
231 2031-03-30 18:00:00 68.211052
232 2031-03-31 00:00:00 68.205093
233 2031-03-31 06:00:00 68.199120
234 2031-03-31 12:00:00 68.193153
235 2031-02-26 00:00:00 68.187195
236 2031-02-26 06:00:00 68.181236
237 2031-02-26 12:00:00 68.175270
238 2031-02-26 18:00:00 68.169304
239 2031-02-27 00:00:00 68.163322
240 2031-02-27 06:00:00 68.169304
....
369 2031-03-31 12:00:00 68.193153
370 2031-03-31 18:00:00 68.258781
371 2031-04-01 00:00:00 67.950096
372 2031-04-01 06:00:00 67.949493
373 2031-04-01 12:00:00 67.949539
374 2031-04-01 18:00:00 67.950241
375 2031-04-02 00:00:00 67.951591
376 2031-04-02 06:00:00 67.953590
377 2031-04-02 12:00:00 67.955589
378 2031-04-02 18:00:00 67.957596
379 2031-04-03 00:00:00 67.959595
380 2031-04-03 06:00:00 67.961601


The dataset continues with the correct timedelta after this blip, but seems to repeat just over a whole month of data (i.e. future.iloc[370] = 2031-03-31 18:00:00 which should be the next timestep after future.iloc[234], and continues with valid data from this point on).I know that the data (other than the repeated month) is valid, so I need to try an salvage the data if I can. I have a number of these datasets, so I now fear that they may have faulty time steps in them as well.



My goal is to check for an inconsistent timedelta between two points, and either remove the rows with the invalid timedeltas:



 time Temp
220 2031-03-28 00:00:00 68.276657
221 2031-03-28 06:00:00 68.270706
222 2031-03-28 12:00:00 68.264748
223 2031-03-28 18:00:00 68.258781
224 2031-03-29 00:00:00 68.252808
225 2031-03-29 06:00:00 68.246849
226 2031-03-29 12:00:00 68.240883
227 2031-03-29 18:00:00 68.234909
228 2031-03-30 00:00:00 68.228943
229 2031-03-30 06:00:00 68.222984
230 2031-03-30 12:00:00 68.217010
231 2031-03-30 18:00:00 68.211052
232 2031-03-31 00:00:00 68.205093
233 2031-03-31 06:00:00 68.199120
234 2031-03-31 12:00:00 68.193153
235 2031-03-31 18:00:00 68.258781
236 2031-04-01 00:00:00 67.950096
237 2031-04-01 06:00:00 67.949493
238 2031-04-01 12:00:00 67.949539
239 2031-04-01 18:00:00 67.950241
240 2031-04-02 00:00:00 67.951591
241 2031-04-02 06:00:00 67.953590
242 2031-04-02 12:00:00 67.955589
243 2031-04-02 18:00:00 67.957596
244 2031-04-03 00:00:00 67.959595
245 2031-04-03 06:00:00 67.961601


or null all data that is associated with an invalid timedelta:



 time Temp
220 2031-03-28 00:00:00 68.276657
221 2031-03-28 06:00:00 68.270706
222 2031-03-28 12:00:00 68.264748
223 2031-03-28 18:00:00 68.258781
224 2031-03-29 00:00:00 68.252808
225 2031-03-29 06:00:00 68.246849
226 2031-03-29 12:00:00 68.240883
227 2031-03-29 18:00:00 68.234909
228 2031-03-30 00:00:00 68.228943
229 2031-03-30 06:00:00 68.222984
230 2031-03-30 12:00:00 68.217010
231 2031-03-30 18:00:00 68.211052
232 2031-03-31 00:00:00 68.205093
233 2031-03-31 06:00:00 68.199120
234 2031-03-31 12:00:00 68.193153
235 2031-02-26 00:00:00 NaN
236 2031-02-26 06:00:00 NaN
237 2031-02-26 12:00:00 NaN
238 2031-02-26 18:00:00 NaN
239 2031-02-27 00:00:00 NaN
240 2031-02-27 06:00:00 NaN
....
369 2031-03-31 12:00:00 NaN
370 2031-03-31 18:00:00 68.258781
371 2031-04-01 00:00:00 67.950096
372 2031-04-01 06:00:00 67.949493
373 2031-04-01 12:00:00 67.949539
374 2031-04-01 18:00:00 67.950241
375 2031-04-02 00:00:00 67.951591
376 2031-04-02 06:00:00 67.953590
377 2031-04-02 12:00:00 67.955589
378 2031-04-02 18:00:00 67.957596
379 2031-04-03 00:00:00 67.959595
380 2031-04-03 06:00:00 67.961601


The real problem I can't fully wrap my head around is that only future.iloc[235] is an invalid timedelta. future.iloc[236:270] are still technically correct 6H timesteps, they have just been offset, which causes the duplication. So to fully remove invalid data, I need to identify both the invalid timedelta as well as the valid timedeltas that create the duplicate data.



I have attempted to create a comparison date range with pd.date_range(start=future.iloc[0].time, end=future.iloc[-1].time, freq='6H'), and iterate through my rows to find faulty values. However, I have not been able to come up with a solution that will actually identify and remove the faulty rows.



Any ideas on how to do this? I assumed pandas would have some built-in functionality for something like this, but haven't been able to find anything substantial that fits my needs.



Bonus: Every check that I have tried seems to take up to minute to run through about 30,000 rows of data. Does this number of rows warrant this time usage iterate through?










share|improve this question
























  • What exactly do you mean by "remove the faulty rows, or null all data that is associated with these rows"? When an inconsistent timedelta is found, you want something like removing rows with dates on the same day ?

    – jmiguel
    Mar 9 at 4:37











  • @jmiguel Yes, as well as any data associated with the invalid timedelta. I added some info to my question that will hopefully clarify this further.

    – k.mcgee
    Mar 9 at 8:21


















0















I looked for an answer for this for a while but haven't been able to find anything, so forgive me if this question has been asked before...



I have some 6-hourly timeseries data future of future temperature projections for the years 2031-2050. Upon looking at the data, I notice that there is some faulty timedeltas in the dataset starting at future.iloc[234]:



future.iloc[220:281]

time Temp
220 2031-03-28 00:00:00 68.276657
221 2031-03-28 06:00:00 68.270706
222 2031-03-28 12:00:00 68.264748
223 2031-03-28 18:00:00 68.258781
224 2031-03-29 00:00:00 68.252808
225 2031-03-29 06:00:00 68.246849
226 2031-03-29 12:00:00 68.240883
227 2031-03-29 18:00:00 68.234909
228 2031-03-30 00:00:00 68.228943
229 2031-03-30 06:00:00 68.222984
230 2031-03-30 12:00:00 68.217010
231 2031-03-30 18:00:00 68.211052
232 2031-03-31 00:00:00 68.205093
233 2031-03-31 06:00:00 68.199120
234 2031-03-31 12:00:00 68.193153
235 2031-02-26 00:00:00 68.187195
236 2031-02-26 06:00:00 68.181236
237 2031-02-26 12:00:00 68.175270
238 2031-02-26 18:00:00 68.169304
239 2031-02-27 00:00:00 68.163322
240 2031-02-27 06:00:00 68.169304
....
369 2031-03-31 12:00:00 68.193153
370 2031-03-31 18:00:00 68.258781
371 2031-04-01 00:00:00 67.950096
372 2031-04-01 06:00:00 67.949493
373 2031-04-01 12:00:00 67.949539
374 2031-04-01 18:00:00 67.950241
375 2031-04-02 00:00:00 67.951591
376 2031-04-02 06:00:00 67.953590
377 2031-04-02 12:00:00 67.955589
378 2031-04-02 18:00:00 67.957596
379 2031-04-03 00:00:00 67.959595
380 2031-04-03 06:00:00 67.961601


The dataset continues with the correct timedelta after this blip, but seems to repeat just over a whole month of data (i.e. future.iloc[370] = 2031-03-31 18:00:00 which should be the next timestep after future.iloc[234], and continues with valid data from this point on).I know that the data (other than the repeated month) is valid, so I need to try an salvage the data if I can. I have a number of these datasets, so I now fear that they may have faulty time steps in them as well.



My goal is to check for an inconsistent timedelta between two points, and either remove the rows with the invalid timedeltas:



 time Temp
220 2031-03-28 00:00:00 68.276657
221 2031-03-28 06:00:00 68.270706
222 2031-03-28 12:00:00 68.264748
223 2031-03-28 18:00:00 68.258781
224 2031-03-29 00:00:00 68.252808
225 2031-03-29 06:00:00 68.246849
226 2031-03-29 12:00:00 68.240883
227 2031-03-29 18:00:00 68.234909
228 2031-03-30 00:00:00 68.228943
229 2031-03-30 06:00:00 68.222984
230 2031-03-30 12:00:00 68.217010
231 2031-03-30 18:00:00 68.211052
232 2031-03-31 00:00:00 68.205093
233 2031-03-31 06:00:00 68.199120
234 2031-03-31 12:00:00 68.193153
235 2031-03-31 18:00:00 68.258781
236 2031-04-01 00:00:00 67.950096
237 2031-04-01 06:00:00 67.949493
238 2031-04-01 12:00:00 67.949539
239 2031-04-01 18:00:00 67.950241
240 2031-04-02 00:00:00 67.951591
241 2031-04-02 06:00:00 67.953590
242 2031-04-02 12:00:00 67.955589
243 2031-04-02 18:00:00 67.957596
244 2031-04-03 00:00:00 67.959595
245 2031-04-03 06:00:00 67.961601


or null all data that is associated with an invalid timedelta:



 time Temp
220 2031-03-28 00:00:00 68.276657
221 2031-03-28 06:00:00 68.270706
222 2031-03-28 12:00:00 68.264748
223 2031-03-28 18:00:00 68.258781
224 2031-03-29 00:00:00 68.252808
225 2031-03-29 06:00:00 68.246849
226 2031-03-29 12:00:00 68.240883
227 2031-03-29 18:00:00 68.234909
228 2031-03-30 00:00:00 68.228943
229 2031-03-30 06:00:00 68.222984
230 2031-03-30 12:00:00 68.217010
231 2031-03-30 18:00:00 68.211052
232 2031-03-31 00:00:00 68.205093
233 2031-03-31 06:00:00 68.199120
234 2031-03-31 12:00:00 68.193153
235 2031-02-26 00:00:00 NaN
236 2031-02-26 06:00:00 NaN
237 2031-02-26 12:00:00 NaN
238 2031-02-26 18:00:00 NaN
239 2031-02-27 00:00:00 NaN
240 2031-02-27 06:00:00 NaN
....
369 2031-03-31 12:00:00 NaN
370 2031-03-31 18:00:00 68.258781
371 2031-04-01 00:00:00 67.950096
372 2031-04-01 06:00:00 67.949493
373 2031-04-01 12:00:00 67.949539
374 2031-04-01 18:00:00 67.950241
375 2031-04-02 00:00:00 67.951591
376 2031-04-02 06:00:00 67.953590
377 2031-04-02 12:00:00 67.955589
378 2031-04-02 18:00:00 67.957596
379 2031-04-03 00:00:00 67.959595
380 2031-04-03 06:00:00 67.961601


The real problem I can't fully wrap my head around is that only future.iloc[235] is an invalid timedelta. future.iloc[236:270] are still technically correct 6H timesteps, they have just been offset, which causes the duplication. So to fully remove invalid data, I need to identify both the invalid timedelta as well as the valid timedeltas that create the duplicate data.



I have attempted to create a comparison date range with pd.date_range(start=future.iloc[0].time, end=future.iloc[-1].time, freq='6H'), and iterate through my rows to find faulty values. However, I have not been able to come up with a solution that will actually identify and remove the faulty rows.



Any ideas on how to do this? I assumed pandas would have some built-in functionality for something like this, but haven't been able to find anything substantial that fits my needs.



Bonus: Every check that I have tried seems to take up to minute to run through about 30,000 rows of data. Does this number of rows warrant this time usage iterate through?










share|improve this question
























  • What exactly do you mean by "remove the faulty rows, or null all data that is associated with these rows"? When an inconsistent timedelta is found, you want something like removing rows with dates on the same day ?

    – jmiguel
    Mar 9 at 4:37











  • @jmiguel Yes, as well as any data associated with the invalid timedelta. I added some info to my question that will hopefully clarify this further.

    – k.mcgee
    Mar 9 at 8:21














0












0








0








I looked for an answer for this for a while but haven't been able to find anything, so forgive me if this question has been asked before...



I have some 6-hourly timeseries data future of future temperature projections for the years 2031-2050. Upon looking at the data, I notice that there is some faulty timedeltas in the dataset starting at future.iloc[234]:



future.iloc[220:281]

time Temp
220 2031-03-28 00:00:00 68.276657
221 2031-03-28 06:00:00 68.270706
222 2031-03-28 12:00:00 68.264748
223 2031-03-28 18:00:00 68.258781
224 2031-03-29 00:00:00 68.252808
225 2031-03-29 06:00:00 68.246849
226 2031-03-29 12:00:00 68.240883
227 2031-03-29 18:00:00 68.234909
228 2031-03-30 00:00:00 68.228943
229 2031-03-30 06:00:00 68.222984
230 2031-03-30 12:00:00 68.217010
231 2031-03-30 18:00:00 68.211052
232 2031-03-31 00:00:00 68.205093
233 2031-03-31 06:00:00 68.199120
234 2031-03-31 12:00:00 68.193153
235 2031-02-26 00:00:00 68.187195
236 2031-02-26 06:00:00 68.181236
237 2031-02-26 12:00:00 68.175270
238 2031-02-26 18:00:00 68.169304
239 2031-02-27 00:00:00 68.163322
240 2031-02-27 06:00:00 68.169304
....
369 2031-03-31 12:00:00 68.193153
370 2031-03-31 18:00:00 68.258781
371 2031-04-01 00:00:00 67.950096
372 2031-04-01 06:00:00 67.949493
373 2031-04-01 12:00:00 67.949539
374 2031-04-01 18:00:00 67.950241
375 2031-04-02 00:00:00 67.951591
376 2031-04-02 06:00:00 67.953590
377 2031-04-02 12:00:00 67.955589
378 2031-04-02 18:00:00 67.957596
379 2031-04-03 00:00:00 67.959595
380 2031-04-03 06:00:00 67.961601


The dataset continues with the correct timedelta after this blip, but seems to repeat just over a whole month of data (i.e. future.iloc[370] = 2031-03-31 18:00:00 which should be the next timestep after future.iloc[234], and continues with valid data from this point on).I know that the data (other than the repeated month) is valid, so I need to try an salvage the data if I can. I have a number of these datasets, so I now fear that they may have faulty time steps in them as well.



My goal is to check for an inconsistent timedelta between two points, and either remove the rows with the invalid timedeltas:



 time Temp
220 2031-03-28 00:00:00 68.276657
221 2031-03-28 06:00:00 68.270706
222 2031-03-28 12:00:00 68.264748
223 2031-03-28 18:00:00 68.258781
224 2031-03-29 00:00:00 68.252808
225 2031-03-29 06:00:00 68.246849
226 2031-03-29 12:00:00 68.240883
227 2031-03-29 18:00:00 68.234909
228 2031-03-30 00:00:00 68.228943
229 2031-03-30 06:00:00 68.222984
230 2031-03-30 12:00:00 68.217010
231 2031-03-30 18:00:00 68.211052
232 2031-03-31 00:00:00 68.205093
233 2031-03-31 06:00:00 68.199120
234 2031-03-31 12:00:00 68.193153
235 2031-03-31 18:00:00 68.258781
236 2031-04-01 00:00:00 67.950096
237 2031-04-01 06:00:00 67.949493
238 2031-04-01 12:00:00 67.949539
239 2031-04-01 18:00:00 67.950241
240 2031-04-02 00:00:00 67.951591
241 2031-04-02 06:00:00 67.953590
242 2031-04-02 12:00:00 67.955589
243 2031-04-02 18:00:00 67.957596
244 2031-04-03 00:00:00 67.959595
245 2031-04-03 06:00:00 67.961601


or null all data that is associated with an invalid timedelta:



 time Temp
220 2031-03-28 00:00:00 68.276657
221 2031-03-28 06:00:00 68.270706
222 2031-03-28 12:00:00 68.264748
223 2031-03-28 18:00:00 68.258781
224 2031-03-29 00:00:00 68.252808
225 2031-03-29 06:00:00 68.246849
226 2031-03-29 12:00:00 68.240883
227 2031-03-29 18:00:00 68.234909
228 2031-03-30 00:00:00 68.228943
229 2031-03-30 06:00:00 68.222984
230 2031-03-30 12:00:00 68.217010
231 2031-03-30 18:00:00 68.211052
232 2031-03-31 00:00:00 68.205093
233 2031-03-31 06:00:00 68.199120
234 2031-03-31 12:00:00 68.193153
235 2031-02-26 00:00:00 NaN
236 2031-02-26 06:00:00 NaN
237 2031-02-26 12:00:00 NaN
238 2031-02-26 18:00:00 NaN
239 2031-02-27 00:00:00 NaN
240 2031-02-27 06:00:00 NaN
....
369 2031-03-31 12:00:00 NaN
370 2031-03-31 18:00:00 68.258781
371 2031-04-01 00:00:00 67.950096
372 2031-04-01 06:00:00 67.949493
373 2031-04-01 12:00:00 67.949539
374 2031-04-01 18:00:00 67.950241
375 2031-04-02 00:00:00 67.951591
376 2031-04-02 06:00:00 67.953590
377 2031-04-02 12:00:00 67.955589
378 2031-04-02 18:00:00 67.957596
379 2031-04-03 00:00:00 67.959595
380 2031-04-03 06:00:00 67.961601


The real problem I can't fully wrap my head around is that only future.iloc[235] is an invalid timedelta. future.iloc[236:270] are still technically correct 6H timesteps, they have just been offset, which causes the duplication. So to fully remove invalid data, I need to identify both the invalid timedelta as well as the valid timedeltas that create the duplicate data.



I have attempted to create a comparison date range with pd.date_range(start=future.iloc[0].time, end=future.iloc[-1].time, freq='6H'), and iterate through my rows to find faulty values. However, I have not been able to come up with a solution that will actually identify and remove the faulty rows.



Any ideas on how to do this? I assumed pandas would have some built-in functionality for something like this, but haven't been able to find anything substantial that fits my needs.



Bonus: Every check that I have tried seems to take up to minute to run through about 30,000 rows of data. Does this number of rows warrant this time usage iterate through?










share|improve this question
















I looked for an answer for this for a while but haven't been able to find anything, so forgive me if this question has been asked before...



I have some 6-hourly timeseries data future of future temperature projections for the years 2031-2050. Upon looking at the data, I notice that there is some faulty timedeltas in the dataset starting at future.iloc[234]:



future.iloc[220:281]

time Temp
220 2031-03-28 00:00:00 68.276657
221 2031-03-28 06:00:00 68.270706
222 2031-03-28 12:00:00 68.264748
223 2031-03-28 18:00:00 68.258781
224 2031-03-29 00:00:00 68.252808
225 2031-03-29 06:00:00 68.246849
226 2031-03-29 12:00:00 68.240883
227 2031-03-29 18:00:00 68.234909
228 2031-03-30 00:00:00 68.228943
229 2031-03-30 06:00:00 68.222984
230 2031-03-30 12:00:00 68.217010
231 2031-03-30 18:00:00 68.211052
232 2031-03-31 00:00:00 68.205093
233 2031-03-31 06:00:00 68.199120
234 2031-03-31 12:00:00 68.193153
235 2031-02-26 00:00:00 68.187195
236 2031-02-26 06:00:00 68.181236
237 2031-02-26 12:00:00 68.175270
238 2031-02-26 18:00:00 68.169304
239 2031-02-27 00:00:00 68.163322
240 2031-02-27 06:00:00 68.169304
....
369 2031-03-31 12:00:00 68.193153
370 2031-03-31 18:00:00 68.258781
371 2031-04-01 00:00:00 67.950096
372 2031-04-01 06:00:00 67.949493
373 2031-04-01 12:00:00 67.949539
374 2031-04-01 18:00:00 67.950241
375 2031-04-02 00:00:00 67.951591
376 2031-04-02 06:00:00 67.953590
377 2031-04-02 12:00:00 67.955589
378 2031-04-02 18:00:00 67.957596
379 2031-04-03 00:00:00 67.959595
380 2031-04-03 06:00:00 67.961601


The dataset continues with the correct timedelta after this blip, but seems to repeat just over a whole month of data (i.e. future.iloc[370] = 2031-03-31 18:00:00 which should be the next timestep after future.iloc[234], and continues with valid data from this point on).I know that the data (other than the repeated month) is valid, so I need to try an salvage the data if I can. I have a number of these datasets, so I now fear that they may have faulty time steps in them as well.



My goal is to check for an inconsistent timedelta between two points, and either remove the rows with the invalid timedeltas:



 time Temp
220 2031-03-28 00:00:00 68.276657
221 2031-03-28 06:00:00 68.270706
222 2031-03-28 12:00:00 68.264748
223 2031-03-28 18:00:00 68.258781
224 2031-03-29 00:00:00 68.252808
225 2031-03-29 06:00:00 68.246849
226 2031-03-29 12:00:00 68.240883
227 2031-03-29 18:00:00 68.234909
228 2031-03-30 00:00:00 68.228943
229 2031-03-30 06:00:00 68.222984
230 2031-03-30 12:00:00 68.217010
231 2031-03-30 18:00:00 68.211052
232 2031-03-31 00:00:00 68.205093
233 2031-03-31 06:00:00 68.199120
234 2031-03-31 12:00:00 68.193153
235 2031-03-31 18:00:00 68.258781
236 2031-04-01 00:00:00 67.950096
237 2031-04-01 06:00:00 67.949493
238 2031-04-01 12:00:00 67.949539
239 2031-04-01 18:00:00 67.950241
240 2031-04-02 00:00:00 67.951591
241 2031-04-02 06:00:00 67.953590
242 2031-04-02 12:00:00 67.955589
243 2031-04-02 18:00:00 67.957596
244 2031-04-03 00:00:00 67.959595
245 2031-04-03 06:00:00 67.961601


or null all data that is associated with an invalid timedelta:



 time Temp
220 2031-03-28 00:00:00 68.276657
221 2031-03-28 06:00:00 68.270706
222 2031-03-28 12:00:00 68.264748
223 2031-03-28 18:00:00 68.258781
224 2031-03-29 00:00:00 68.252808
225 2031-03-29 06:00:00 68.246849
226 2031-03-29 12:00:00 68.240883
227 2031-03-29 18:00:00 68.234909
228 2031-03-30 00:00:00 68.228943
229 2031-03-30 06:00:00 68.222984
230 2031-03-30 12:00:00 68.217010
231 2031-03-30 18:00:00 68.211052
232 2031-03-31 00:00:00 68.205093
233 2031-03-31 06:00:00 68.199120
234 2031-03-31 12:00:00 68.193153
235 2031-02-26 00:00:00 NaN
236 2031-02-26 06:00:00 NaN
237 2031-02-26 12:00:00 NaN
238 2031-02-26 18:00:00 NaN
239 2031-02-27 00:00:00 NaN
240 2031-02-27 06:00:00 NaN
....
369 2031-03-31 12:00:00 NaN
370 2031-03-31 18:00:00 68.258781
371 2031-04-01 00:00:00 67.950096
372 2031-04-01 06:00:00 67.949493
373 2031-04-01 12:00:00 67.949539
374 2031-04-01 18:00:00 67.950241
375 2031-04-02 00:00:00 67.951591
376 2031-04-02 06:00:00 67.953590
377 2031-04-02 12:00:00 67.955589
378 2031-04-02 18:00:00 67.957596
379 2031-04-03 00:00:00 67.959595
380 2031-04-03 06:00:00 67.961601


The real problem I can't fully wrap my head around is that only future.iloc[235] is an invalid timedelta. future.iloc[236:270] are still technically correct 6H timesteps, they have just been offset, which causes the duplication. So to fully remove invalid data, I need to identify both the invalid timedelta as well as the valid timedeltas that create the duplicate data.



I have attempted to create a comparison date range with pd.date_range(start=future.iloc[0].time, end=future.iloc[-1].time, freq='6H'), and iterate through my rows to find faulty values. However, I have not been able to come up with a solution that will actually identify and remove the faulty rows.



Any ideas on how to do this? I assumed pandas would have some built-in functionality for something like this, but haven't been able to find anything substantial that fits my needs.



Bonus: Every check that I have tried seems to take up to minute to run through about 30,000 rows of data. Does this number of rows warrant this time usage iterate through?







python pandas time-series python-xarray






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 9 at 8:20







k.mcgee

















asked Mar 9 at 2:28









k.mcgeek.mcgee

565




565












  • What exactly do you mean by "remove the faulty rows, or null all data that is associated with these rows"? When an inconsistent timedelta is found, you want something like removing rows with dates on the same day ?

    – jmiguel
    Mar 9 at 4:37











  • @jmiguel Yes, as well as any data associated with the invalid timedelta. I added some info to my question that will hopefully clarify this further.

    – k.mcgee
    Mar 9 at 8:21


















  • What exactly do you mean by "remove the faulty rows, or null all data that is associated with these rows"? When an inconsistent timedelta is found, you want something like removing rows with dates on the same day ?

    – jmiguel
    Mar 9 at 4:37











  • @jmiguel Yes, as well as any data associated with the invalid timedelta. I added some info to my question that will hopefully clarify this further.

    – k.mcgee
    Mar 9 at 8:21

















What exactly do you mean by "remove the faulty rows, or null all data that is associated with these rows"? When an inconsistent timedelta is found, you want something like removing rows with dates on the same day ?

– jmiguel
Mar 9 at 4:37





What exactly do you mean by "remove the faulty rows, or null all data that is associated with these rows"? When an inconsistent timedelta is found, you want something like removing rows with dates on the same day ?

– jmiguel
Mar 9 at 4:37













@jmiguel Yes, as well as any data associated with the invalid timedelta. I added some info to my question that will hopefully clarify this further.

– k.mcgee
Mar 9 at 8:21






@jmiguel Yes, as well as any data associated with the invalid timedelta. I added some info to my question that will hopefully clarify this further.

– k.mcgee
Mar 9 at 8:21













1 Answer
1






active

oldest

votes


















0














to identify the errors maybe to do this sort of test:



1) you group by day
2) you trap the group with number items > 0 and < 4
3) you have the list of errors, you could drop the corresponding rows



errorlist=[]
def f(g):
if g.shape[0] > 0 and g.shape[0] < 4:
errorlist.append(g.index[0])
df.set_index('time').groupby(pd.Grouper(freq='D')).apply(f)

print(errorlist)





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55073437%2fidentifying-and-removing-invalid-time-steps-in-a-pandas-time-series%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    to identify the errors maybe to do this sort of test:



    1) you group by day
    2) you trap the group with number items > 0 and < 4
    3) you have the list of errors, you could drop the corresponding rows



    errorlist=[]
    def f(g):
    if g.shape[0] > 0 and g.shape[0] < 4:
    errorlist.append(g.index[0])
    df.set_index('time').groupby(pd.Grouper(freq='D')).apply(f)

    print(errorlist)





    share|improve this answer



























      0














      to identify the errors maybe to do this sort of test:



      1) you group by day
      2) you trap the group with number items > 0 and < 4
      3) you have the list of errors, you could drop the corresponding rows



      errorlist=[]
      def f(g):
      if g.shape[0] > 0 and g.shape[0] < 4:
      errorlist.append(g.index[0])
      df.set_index('time').groupby(pd.Grouper(freq='D')).apply(f)

      print(errorlist)





      share|improve this answer

























        0












        0








        0







        to identify the errors maybe to do this sort of test:



        1) you group by day
        2) you trap the group with number items > 0 and < 4
        3) you have the list of errors, you could drop the corresponding rows



        errorlist=[]
        def f(g):
        if g.shape[0] > 0 and g.shape[0] < 4:
        errorlist.append(g.index[0])
        df.set_index('time').groupby(pd.Grouper(freq='D')).apply(f)

        print(errorlist)





        share|improve this answer













        to identify the errors maybe to do this sort of test:



        1) you group by day
        2) you trap the group with number items > 0 and < 4
        3) you have the list of errors, you could drop the corresponding rows



        errorlist=[]
        def f(g):
        if g.shape[0] > 0 and g.shape[0] < 4:
        errorlist.append(g.index[0])
        df.set_index('time').groupby(pd.Grouper(freq='D')).apply(f)

        print(errorlist)






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 9 at 5:21









        FrenchyFrenchy

        2,0002517




        2,0002517





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55073437%2fidentifying-and-removing-invalid-time-steps-in-a-pandas-time-series%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

            Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

            2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived