How to find the position of the first occurrence of a value greater than a given value?
MACHINE LEARNING RECIPES DATA CLEANING PYTHON DATA MUNGING PANDAS CHEATSHEET     ALL TAGS

How to find the position of the first occurrence of a value greater than a given value?

How to find the position of the first occurrence of a value greater than a given value?

This recipe helps you find the position of the first occurrence of a value greater than a given value

0

Recipe Objective

How to find the position of the first occurrence of a value greater than a given value? So this is also possible by using the "next" and "enumerate" function available in python. By using the "next" function which will returns the iterator to that element that has been using the "enumerate" funtion. In this we simply put the condition for enumerate and "next" will pick up the appropriate element index.

Step 1 - Take Sample Data

Sample_data = [1,2,3,3.5,4,5,6,7,8,9,0] print("This is a Sample list :", Sample_data)
This is a Sample list : [1, 2, 3, 3.5, 4, 5, 6, 7, 8, 9, 0]

Step 2 - Find the next occurence

next_occ = next(x for x, elements in enumerate(Sample_data) if elements > 3.1)

Step 3 - Print the results

print("This is output result for finding next occurence :", next_occ)
This is output result for finding next occurence : 3

Relevant Projects

Machine Learning project for Retail Price Optimization
In this machine learning pricing project, we implement a retail price optimization algorithm using regression trees. This is one of the first steps to building a dynamic pricing model.

Data Science Project - Instacart Market Basket Analysis
Data Science Project - Build a recommendation engine which will predict the products to be purchased by an Instacart consumer again.

Predict Macro Economic Trends using Kaggle Financial Dataset
In this machine learning project, you will uncover the predictive value in an uncertain world by using various artificial intelligence, machine learning, advanced regression and feature transformation techniques.

Topic modelling using Kmeans clustering to group customer reviews
In this Kmeans clustering machine learning project, you will perform topic modelling in order to group customer reviews based on recurring patterns.

Identifying Product Bundles from Sales Data Using R Language
In this data science project in R, we are going to talk about subjective segmentation which is a clustering technique to find out product bundles in sales data.

Learn to prepare data for your next machine learning project
Text data requires special preparation before you can start using it for any machine learning project.In this ML project, you will learn about applying Machine Learning models to create classifiers and learn how to make sense of textual data.

NLP and Deep Learning For Fake News Classification in Python
In this project you will use Python to implement various machine learning methods( RNN, LSTM, GRU) for fake news classification.

Expedia Hotel Recommendations Data Science Project
In this data science project, you will contextualize customer data and predict the likelihood a customer will stay at 100 different hotel groups.

Machine Learning or Predictive Models in IoT - Energy Prediction Use Case
In this machine learning and IoT project, we are going to test out the experimental data using various predictive models and train the models and break the energy usage.

Forecast Inventory demand using historical sales data in R
In this machine learning project, you will develop a machine learning model to accurately forecast inventory demand based on historical sales data.