简体   繁体   English

我如何删除包含日期时间非连续的行(数据框)

[英]how can i drop rows that contains datetime non consecutive (dataframe)

I want to create a function that takes dataframe as input and returns it after doing these operations:我想创建一个 function 以dataframe作为输入并在执行以下操作后返回它:

  1. Count the number of rows that if we compare it with rows before it and after it we get consecutive date.计算如果我们将它与它之前和之后的行比较我们得到连续日期的行数。

  2. Drop all the rows that do not fulfill the condition above删除所有不满足上述条件的行

The dataframe: dataframe:

For your question you can use date_range function.对于您的问题,您可以使用 date_range function。 You can use it like this你可以像这样使用它

import pandas as pd
range=pd.date_range('START DATE','END DATE',freq='1D')
df = pd.DataFrame({'a': range(NO OF PERIODS)}, index=range)  
print (df) 

This will give you all the dates which are continuous as daily, starting from that date.这将为您提供从该日期开始每天连续的所有日期。 And you can use these continuous dates as your index.您可以使用这些连续日期作为您的索引。 Thus rows not fulfilling your wish will be skipped.因此,不满足您愿望的行将被跳过。

For detailed knowledge of date_range you can refer enter link description here有关 date_range 的详细知识,您可以参考在此处输入链接描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM