Chapter 1: Python Pandas-I

Type A (Very Short Questions)

1. What is the significance of Pandas library?

2. Name some common data structures of Python’s Pandas library.

3. How is Series object different from and similar to ndarrays ? Support your answer with example.

4. Write commands to print following details of a Series object seal.

5. Given following Series objects:

                   S1                      S2
               0      3                 0     12
               1      5                 2     10
               2      6                 3     15
               4      10                4     20
               5      12                6     27

(a) What will be the result of S1 + S2 ?
(b) What will be the result of S1 – S2 ?

6. Given a dataframe df as shown below:

     A        B        D
0  15      17      19
1  16      18      20
2  20      21      22

What will be the result of following code segment ?
(a) df[‘C’] = np.NaN
(b) df[‘C’] = [2,5]
(c) df[‘C’] = [12, 15, 27]

7. Write the code segment to list the following, from Dataframe namely sales.
a) List only columns ‘Item’ and ‘revenue’
b) List rows from 3 to 7
c) List the value of cell in 5th row, ‘Item’ column.

8. How would you add a new column namely ‘val’ to a Dataframe df that has 10 rows in it and has columns as ‘Item’, ‘Qty’, ‘Price’ ? You can choose to put any values of your choice.

9. Write code statement for Dataframe df for the following:
a) Delete an existing column from it.
b) Delete row from 3 to 6 from it.
c) Check the Dataframe has any missing values.
d) Fill all missing values with 999 in it.

10. Write statement(s) to delete a row from Dataframe.

11. Write statement(s) to delete a column from a Dataframe.

12. Write the statement to change the value at 5th row, 6th column in a Dataframe df.

13. Write the statement to change the value to 750 at 4th row to 9th row, 7th column in Dataframe df.

14. What is the difference between iloc and loc with respect to Dataframe ?

15. What is the difference between iat and at.

16. How would you delete column from a Dataframe.

17. How would you delete rows from Dataframe ?

18. Which function would you use to rename the index/column names in a Dataframe?

error: Content is protected !!