• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: How to get first occurrence of specific value of one column but only if it’s there at least 5 consecutive rows below each other

Resolved: How to get first occurrence of specific value of one column but only if it’s there at least 5 consecutive rows below each other

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

lets assume I have pandas dataframe looking like this:
Now, I’d like to know first occurrence at what “Time/ps” the “%” decreases to 0.0 but only under condition that the 0 (zeroes) are there at least 5 consecutive rows below each other. I tried to do it with this code and it works partially:
However, the problem is that I don’t know how to get information when there are 0.0’s in the “%”-column at least 5 consecutive rows under each other. This code prints all occurrences and I could scroll it but I want to do it automatically. My desired output would look something like this: Time/ps: 9
Thank You for suggestions

Answer:

The naive answer could be to take your code and do something like this:
A nicer way could be like this:
I took you groupby code and then used filter to filter out groups with length less than 5.
This gives this dataframe:
You said you want the first occurrence:

If you have better answer, please add a comment about this, thank you!

dataframe python
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: When converting markdown to latex with pandoc, how can I end a block before the next heading?

26/03/2023

Resolved: TYPO3 SQL error: Field ‘tx_imagezoom_set’ doesn’t have a default value

26/03/2023

Resolved: std::regex_replace to replace multiple combinations

26/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.