chevron_left
Series Cookbook
Appending values to a SeriesApplying a function to SeriesBinning values in a SeriesChanging data type of SeriesChecking if a value is NaN in Pandas SeriesChecking if all values are NaN in SeriesChecking if all values in a Series are uniqueChecking if Series has missing valuesConverting Python list to SeriesConverting Series of lists into DataFrameConverting Series to a Numpy arrayConverting Series to Python listCounting frequency of values in SeriesCreating a Series of zeroesCreating a Series with constant valueFiltering strings based on length in SeriesFiltering values of a SeriesGetting frequency counts of values in intervalsGetting index of largest valueGetting index of smallest valueGetting index of value in SeriesGetting integer index of largest valueGetting integer index of smallest valueGetting integer index of value in SeriesGetting intersection of SeriesGetting length of each string in SeriesGetting list of integer indices where value is boolean True in SeriesGetting the index of the nth value in SeriesGetting the most frequent value in SeriesGetting value of Series using integer indexGrouping Series by its valuesHandling error - "Truth value of a Series is ambiguous"Inverting a Series of booleansRemoving missing values from a SeriesRemoving substrings from strings in a SeriesRemoving values from SeriesResetting index of SeriesSorting values in a SeriesSplitting strings based on spaceStripping leading and trailing whitespaceTaking the floor or ceiling of values in SeriesUsing index.get_loc(~) for multiple values
check_circle
Mark as learned thumb_up
0
thumb_down
0
chat_bubble_outline
0
auto_stories new
settings
Removing values from Series in Pandas
Pandas
chevron_rightCookbooks
chevron_rightSeries Cookbook
schedule Jul 1, 2022
Last updated local_offer Python●Pandas
Tags tocTable of Contents
expand_more Check out the interactive map of data science
Removing values using integer indices
To remove values using integer indices, use the drop(~)
method like so:
Here, a new Series is returned and so the original s
is kept intact. To directly modify s
, set inplace=True
.
Removing values using index labels
To remove values using index labels, use the drop(~)
method:
Removing occurrences of values
To remove all occurrences of the value 5
:
To explain, we first fetch a boolean mask where True
indicates a value that is not 5
:
s != 5
0 True1 False2 True3 Falsedtype: bool
We then pass this mask into the loc
property to fetch the entries that correspond to True
in the mask.
Removing values using slicing
To remove the values from integer index 1
(inclusive) to 3
(exclusive):
Published by Isshin Inada
Edited by 0 others
Did you find this page useful?
thumb_up
thumb_down
Ask a question or leave a feedback...
thumb_up
0
thumb_down
0
chat_bubble_outline
0
settings
Enjoy our search
Hit / to insta-search docs and recipes!