Class 12 Informatics Practices 065 Chapter 1 Python Pandas 1 Question Answer

Class 12 Informatics Practices (065)

Chapter 1 : Python Pandas – I

Important Question Answer

1. What is Pandas or Python Pandas?

Answer: Pandas or Python Pandas is Python’s library for data analysis. Pandas makes available various tools for data analysis and makes it a simple and easy process as compared to other tools.

Pandas is an open source, BSD library built for Python programming language. Pandas offers high-performance, easy to use data structures (like Series and DataFrame) and data analysis tools.

2. Write full form of Pandas?

Answer: Pandas stands for Panel Data System.

3. Who is the author Python Pandas?

Answer: The main author of Pandas is Wes McKinney.

4. How can you install pandas?

Answer: To install pandas follows these steps :-

(a) Press Windows button and type cmd in search box, press enter key.

(b) Type given command on command prompt.

pip install pandas

and press enter key. It will install pandas automatically on your computer.

Note : Internet connection is required.

5. Why you need to use Pandas?

Answer: The most important features of pandas are :-

(a) Most suitable for data analysis.

(b) allow to read different types of data format (integer, float, double, etc)

(c) can calculate in all possible ways.

(d) allow to select subset of data from bulky data.

(e) allow to apply operations to independent groups of data.

(f) supports visualization by integrating matplotlib and seaborn etc. libraries.

6. What do you mean by data structure?

Answer: A Data structure is a particular way of storing and organising data in a computer to apply a specific type of functionality on them.

7. How many types of data structure in Pandas?

Answer: There are three types of data structure in Pandas.

(a) Series

(b) DataFrame

(c) Panel

8. Differentiate between Series and DataFrame.

Answer: Series vs DataFrame

SeriesDataFrame
(i) Series is a 1-Dimensional Data Structure.
(ii) Series allows to store Homogeneous data i.e. similar types of data.
(iii) Series is a value mutable but size immutable.
(i) DataFrame is a 2-Dimensional Data Structure.
(ii) DataFrame allows to store Heterogeneous data i.e. can store different types of data.
(iii) DataFrame is a value mutable and size mutable.

9. How can you import Pandas library?

Answer: The import statement is use to import the pandas library. It can be used in two ways-

(a) Importing library directly.

import pandas

sObj = pandas.Series([10,12,15,25])

(b) Importing library with alias name

import pandas as pd

sObj = pd.Series([10,12,15,25])

10. What is Series?

Answer: A Series is a Pandas data structure that represents a one-dimensional array-like object containing an array of data and an associated array of indexes (Numeric index) or data labels (Labelled index).

11. What is positional index and labelled index?

Answer: When numeric indexes specify the position of data in the series object i.e. indexes are given like 0, 1, 2, 3, …., is known as Positional Indexes.

When indexes are user defined labels, then it is called Labelled Indexes.

12. Which function of Pandas is use to create a Series object?

Answer: Series().

A series type object can be crated in many ways using pandas library’s Series()

13. Write the syntax of Series().

Answer: Basic syntax of Series() is

import pandas as pd

seriesObject = pd.Series(data, index=idx, dypte = datatype)

14. How to create an empty Series object in Python Pandas?

Answer: In Python Pandas, an empty series object by using just Series() method with no parameter.

seriesObject = pandas.Series()

import pandas as pd

seriesObject = pd.Series()

print(seriesObject)

Output:

Series( [ ], dtype : float64)

15. How to create a non-empty Series object in Python Pandas?

Answer: In Python Pandas, to create non-empty series object, you need to pass arguments for data and index as per given syntax.

seriesObject = pd.Series(data, index = idx)

import pandas as pd

seriesObject = pd.Series( [2,5,10,15], index = ['a', 'b', 'c', 'd'])

print(seriesObject)

Output:

16. What’s type of data can be passed to create a non-empty Series object in Python Pandas?

Answer: In Python Pandas, to create non-empty series object, you can pass following types of data. (a) Sequence (b) Dictionary (c) ndarray (NumPy Array) (d) Scalar Value

17. Write statement to create a Series object by passing a list or tuple (Python sequence) as argument in Python Pandas.

Answer:

import pandas as pd
sobj1= pd.Series([1, 4, 6, 8, 10])
sobj2 = pd.Series((1, 4, 6, 8, 10))
sobj3 = pd.Series([1.5, 4.67, 6.98, 8.12])
sobj4 = pd.Series(['a', 'b', 'c', 'd'])
sobj5 = pd.Series(['mycstutorial.in' , True, 6, 39.12])
print(sobj1)
print(sobj2)
print(sobj3)
print(sobj4)
print(sobj5)

Output:

18. Write statement to create a Series object by passing (a) string and (b) List of Strings as an argument in Python Pandas.

Answer: (a) import pandas as pd

sobj = pd.Series(“mycstutorial.in is a very useful website”)

Answer: import pandas as pd

sobj = pd.Series( [“mycstutorial.in”, “is”, “a”, “very”, “useful”, “website”])

19. Write three functions name, which can be use to crate an NumPy array.

Answer: array(), arange(), linspace()

20. Explain briefly about array(), arange() and linspace()

Answer: array(), arange(), & linspace() are methods use to create ndarray. To create a NumPy array, you must be import numpy before using these functions.

import numpy as np

array() : array() function of numpy is use to create a NumPy array.

arr1 = np.array([25,35,62,95])

arr2 = np.array([12, 65, 100, np.NaN, 75])

arange() : arange() means array range. This function is similar to range() function, which create an numpy ndarray.

Syntax : np.range(start, stop, step)

For example :

arr3 = np.arange(5)

print(arr3)

[0, 1, 2, 3, 4]

arr4 = np.arange(15, 30, 3)

print(arr4)

[15 18 21 24 27]

linspace() : linspace() generates an ndarray having linear spaced specified number of values, including start and stop values. This function will generate a sequence of specified numbers between two given values.

Syntax : np.linspace(start, stop, numberofvalues)

>>> arr5 = np.linspace(5,8,6)
>>> arr5
array([5. , 5.6, 6.2, 6.8, 7.4, 8. ])

21. Write a Python Program to create a Series having all even numbers from 1 to 19, including both, using arange() function.

Answer:

import pandas as pd
import numpy as np
sobj = pd.Series(np.arange(2,20, 2)
print(sobj)

22. Can we create a Series object using dictionary? If Yes, then give one example and explain.

Answer: Yes, a dictionary can be used as data to create a series object.

Example:

import pandas as pd

dict1 = {‘Name’: “Anuj”, “Class” : 12, ‘Fee’: 2500.00}

sobj = pd.Series(dict1)

print(sobj)

When you are creating a series object using dictionary object, then keys of the dictionary become index of the Series and values of dictionary become the data of series object.

You cannot copy content of this page

Scroll to Top