O'Reilly logo

Learning pandas - Second Edition by Michael Heydt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Removing rows using a slice

Slicing can be used to remove records from a data frame. It is a process similar to Boolean selection where we select out all of the rows except for the ones you want removed.

Suppose we want to remove all but the first three records from sp500. The slice to perform this task is [:3] which returns the first three rows.

Remember, that since this is a slice, the result is a view into the original data frame. The rows have not been removed from the sp500 data, and changes to these three rows will change the data in sp500. The proper action to prevent this is to make a copy of the slice which results in a new data frame ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required