How to delete rows from pandas dataframe?

To delete a row or n rows from a pandas dataframe you can use following command

DataFrame.drop(labels=None, axis=0, index=None, columns=None, level=None, inplace=False, errors='raise')

Let's assume you have a dataframe with 100 employees data with employee id's ranging from 1 to 100. If you want to drop all employees from dataframe with employee id between 5 and 10. Then you can use following command to do this.

df.drop(df.loc[((df.emp_id >= 5) & (df.emp_id <= 10))].index, inplace=True)

If you want to drop all employees with employee id greater than 90. Then you can modify above as following.

df.drop(df.loc[df.emp_id > 90].index, inplace=True)

 

For more such tips stay tuned.



Was this article helpful?

Top Related Jobs

Top Freelance jobs are waiting for you, View & apply to earn more.



People also searched for

Python Scripting – Learn and Earn
Python Scripting – Learn and Earn
Scripts & Utilities

Welcome to Python programming world! We presume you are trying to find information concerning why and how to get started with Python. Fortunately, an experienced coder in any progr...

Read More
Python script for computational science
Python script for computational science
Scripts & Utilities

Now a days, the popularity of scientific computing environments such as IDL, Maple, Mathematica, Matlab and R has increased considerably. Engineer simply feel more productive in su...

Read More
Everyone wants API expert
Everyone wants API expert
Scripts & Utilities

APIs became so valuable it comprises an oversized part of several businesses’ revenue. Major companies like Google, eBay, Salesforce.com, Amazon, and Expedia are simply many of the...

Read More

You are freelancing Ninja?

Try Toogit Instant Connect today, The new virtual assistant for your freelancing world.


What is Python Script?

Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. Python's simple, easy to learn syntax emphasizes readability and therefore reduces the cost of program maintenance. Python supports modules and packages, which encourages program modularity and code reuse.

What is a Python Script Freelancer?

Python is an interpreted, object-oriented and extensible programming language. Python can run on many different operating systems. A freelancer well versed in Python can handle your workload quite easily. To hire freelance programming help for Python post a job today!

What is a Freelancer?

A freelancer or freelance worker, is a term commonly used for a person who is self-employed and is not necessarily committed to a particular employer long-term.

Why hire a Freelancer instead of full time employee?

If there is a long lead time for them to get up and running, using that investment on a full-time employee might be a better option. And if the position requires oversight, hire an employee. A freelancer might choose to perform the work outside of normal business hours, when you're not able to monitor their progress.

What our users are discussing about Python