I have a Series like this after doing groupby('name') and used mean() function on other column
name
383 3.000000
663 1.000000
726 1.000000
737 9.000000
833 8.166667
Could anyone please show me how to filter out the rows with 1.000000 mean values? Thank you and I greatly appreciate your help.
Sort the Series in Ascending Order By default, the pandas series sort_values() function sorts the series in ascending order. You can also use ascending=True param to explicitly specify to sort in ascending order. Also, if you have any NaN values in the Series, it sort by placing all NaN values at the end.
Pandas str. slice() method is used to slice substrings from a string present in Pandas series object. It is very similar to Python's basic principal of slicing objects that works on [start:stop:step] which means it requires three parameters, where to start, where to end and how much elements to skip.
What does the pandas series.filter () method do? The series.filter () method in the pandas series constructor is used to subset the rows of a series object based on the index labels. The filter method does not work for the content of the series object, it is only applied to the index labels of the series object.
Pandas Series.filter () function returns subset rows or columns of dataframe according to labels in the specified index. Please note that this routine does not filter a dataframe on its contents. The filter is applied to the labels of the index.
Example #1: Use Series.filter () function to filter out some values in the given series object using a regular expressions. import pandas as pd sr = pd.Series ([80, 25, 3, 25, 24, 6]) index_ = ['Coca Cola', 'Sprite', 'Coke', 'Fanta', 'Dew', 'ThumbsUp']
The series.filter () method in the pandas series constructor is used to subset the rows of a series object based on the index labels. The filter method does not work for the content of the series object, it is only applied to the index labels of the series object.
In [5]:
import pandas as pd
test = {
383: 3.000000,
663: 1.000000,
726: 1.000000,
737: 9.000000,
833: 8.166667
}
s = pd.Series(test)
s = s[s != 1]
s
Out[0]:
383 3.000000
737 9.000000
833 8.166667
dtype: float64
From pandas version 0.18+ filtering a series can also be done as below
test = {
383: 3.000000,
663: 1.000000,
726: 1.000000,
737: 9.000000,
833: 8.166667
}
pd.Series(test).where(lambda x : x!=1).dropna()
Checkout: http://pandas.pydata.org/pandas-docs/version/0.18.1/whatsnew.html#method-chaininng-improvements
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With