In the pandas series constructor, the method called dropna() is used to remove missing values from a series object. And it does not update the original series object with removed NaN values instead of updating the original series object, it will return another series object with updated values.
The parameters of the dropna() method are axis, inplace, and how.
Initially, we have created a pandas Series with labeled index values and there are some Nan values present in the series object. After creating a pandas series object we have applied the dropna() method to remove missing values.
Output
Series object:
A 42.0
B NaN
C 55.0
D 42.0
E NaN
F 73.0
G NaN
H 55.0
I 76.0
J 87.0
dtype: float64
A 42.0
C 55.0
D 42.0
F 73.0
H 55.0
I 76.0
J 87.0
dtype: float64
In the above output block, we can see both initial and resultant series objects. The second series object is the output object with removed missing values.
Answers & Comments
Verified answer
Answer:
In the pandas series constructor, the method called dropna() is used to remove missing values from a series object. And it does not update the original series object with removed NaN values instead of updating the original series object, it will return another series object with updated values.
The parameters of the dropna() method are axis, inplace, and how.
Example 1
# importing packages
import pandas as pd
import numpy as np
# Creating Series objects
sr = pd.Series([42, np.nan, 55, 42, np.nan, 73, np.nan, 55, 76, 87], index=list("ABCDEFGHIJ"))
print('Series object:',sr)
# Remove missing elements
result = sr.dropna()
# display output
print(result)
Explanation
Initially, we have created a pandas Series with labeled index values and there are some Nan values present in the series object. After creating a pandas series object we have applied the dropna() method to remove missing values.
Output
Series object:
A 42.0
B NaN
C 55.0
D 42.0
E NaN
F 73.0
G NaN
H 55.0
I 76.0
J 87.0
dtype: float64
A 42.0
C 55.0
D 42.0
F 73.0
H 55.0
I 76.0
J 87.0
dtype: float64
In the above output block, we can see both initial and resultant series objects. The second series object is the output object with removed missing values.
Explanation:
please make me as brilliant plz