0

I want to find the rows that have a same values, after 5 repetitions in sequence. For example, I have this data:

ID. Temperat
23  30.147
24  29.523
25  32
26  32
27  32
28  32
29  32
30  32
31  32
32  32
33  32
34  32
35  32
36  32
37  32
38  29.638

And I want to get the index and the values. But in generic way

This is my code in the moment:

nunique = df.apply(pd.Series.nunique)
cols_to_drop = nunique[nunique == 1].index
df.drop(cols_to_drop, axis=1)

And I want the output like this:

 ID. Temperat

25  32
26  32
27  32
28  32
29  32
30  32
31  32
32  32
33  32
34  32
35  32
36  32
37  32
bern_code
  • 37
  • 4
  • What should be the output for the given example? – YOLO Jul 09 '20 at 15:00
  • IIUC `df.drop_duplicates(subset=['ID.','Temperat'],keep=False)` I don't udnerstand what output you need from above though – Umar.H Jul 09 '20 at 15:01
  • Related: [Removing values that repeat more than 5 times in Pandas DataFrame](https://stackoverflow.com/questions/28109256/removing-values-that-repeat-more-than-5-times-in-pandas-dataframe), [Pandas: Drop consecutive duplicates](https://stackoverflow.com/questions/19463985/pandas-drop-consecutive-duplicates), [Pandas: flag consecutive values](https://stackoverflow.com/questions/40555036/pandas-flag-consecutive-values), – wwii Jul 09 '20 at 15:15

1 Answers1

0

I found a way to resolve this type of problem.

cols = list(df.columns.values)
# Create a DataFrame object
dfObj = pd.DataFrame(df,columns = cols)

# Find a duplicate rows
duplicateDFRow = dfObj[dfObj.duplicated()]
bern_code
  • 37
  • 4