हिंदी

Consider the following code: >>>import pandas as pd >>>import numpy as np >>>s2=pd. Series([12,np.nan,10]) >>>print(s2)

Advertisements
Advertisements

प्रश्न

Consider the following code:

>>>import pandas as pd >>>import numpy as np >>>s2=pd.
Series([12,np.nan,10]) >>>print(s2) 

Find the output of the above code and write a Python statement to count and display only non-null values in the above series.

लघु उत्तरीय
Advertisements

उत्तर

Printing the Series s2 displays the index numbers and values. Because the Series contains a missing value (np.nan), Pandas converts all integer values into floats (float64).

Output:

0 12.0
1 NaN
2 10.0
dtype float64

To count and display only the non-null values (ignoring the NaN), use the .count() method:

print(s2.count())

shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 2: Data Handling using Pandas - I - Intext Questions [पृष्ठ ३५]

APPEARS IN

एनसीईआरटी Informatics Practices [English] Class 12
अध्याय 2 Data Handling using Pandas - I
Intext Questions | Q 4. | पृष्ठ ३५
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×