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.

  • Computer Vision Developer

    $28, Hourly | United States
    Our small company search a developer, who can develop software for recognition road marking lane.
  • Back end engineer needed with Go or Scala experiece

    $18, Hourly | India
    Rewrite of existing code from Python.Our company is a stealth start up in home automation and artificial intelligence.Must have 5 years ples of develo...
  • Break captcha image with Machine Learning

    $50, Fixed | Japan
    The deliverable is a job/script that takes an image (CAPTCHA) as input, and returns the text displayed in the image as a text. The images have a varia...
  • need a website

    $5, Hourly | Romania
    want a good responsive and dynamic website for my personal use
  • Shop bot

    $300, Fixed | United States
    -Proxies can be saved to Proxies tab-Billing info saved in billing tab-captcha harvester (Will discuss)-Key Database (Will discuss)-automation for one...
  • Python Code Review for a Instagram Analytics Project

    $18, Hourly | United Kingdom
    Hi,Need an experienced Python programmer that does peer reviews. The program has the following goals:- Extract information from Instagram- Analyze it-...
  • Azure Python Batch task with input file and parallel compute

    $28, Hourly | Australia
    I have a python script that takes to long to run from a single machine. I want to have the script run across a batch and point to the storage account...
  • Convert Matlab Code into Python and review existing

    $50, Fixed | France
    I would like to write matlab function (findchangepts) into python.Also there is an existing python code to be adjust for plotting timeseries.


People also searched for

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
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
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 Auto proposal today, The new virtual assistant for your freelancing world.