English

Use the DataFrame created in Question 9 above to do the following: a) Display the row labels of Sales. b) Display the column labels of Sales. c) Display the data types of each column of Sales.

Advertisements
Advertisements

Question

Use the DataFrame created in Question 9 above to do the following:

  1. Display the row labels of Sales.
  2. Display the column labels of Sales.
  3. Display the data types of each column of Sales.
  4. Display the dimensions, shape, size and values of Sales.
  5. Display the last two rows of Sales.
  6. Display the first two columns of Sales.
  7. Create a dictionary using the following data. Use this dictionary to create a DataFrame Sales2.
      2018
    Madhu 160000
    Kusum 110000
    Kinshuk 500000
    Ankit 340000
    Shruti 900000
  8. Check if Sales2 is empty or it contains data.
Code Writing
Advertisements

Solution

import pandas as pd
Sales = pd.DataFrame
(
    {
        2014: [100.5, 150.8, 200.9, 30000, 40000],
        2015: [12000, 18000, 22000, 30000, 45000],
        2016: [20000, 50000, 70000, 100000, 125000],
        2017: [50000, 60000, 70000, 80000, 90000]
    },
    index=['Madhu', 'Kusum', 'Kinshuk', 'Ankit', 'Shruti']
)
print(Sales.index)
print(Sales.columns)
print(Sales.dtypes)
print(Sales.ndim)
print(Sales.shape)
print(Sales.size)
print(Sales.values)
print(Sales.tail(2))
print(Sales.iloc[:, :2])
data = {
    2018: [160000, 110000, 500000, 340000, 900000]
}
Sales2 = pd.DataFrame(data, index=['Madhu', 'Kusum', 'Kinshuk', 'Ankit', 'Shruti'])
print(Sales2)
print(Sales2.empty)
shaalaa.com
  Is there an error in this question or solution?
Chapter 2: Data Handling using Pandas - I - Exercise [Page 61]

APPEARS IN

NCERT Informatics Practices [English] Class 12
Chapter 2 Data Handling using Pandas - I
Exercise | Q 10. | Page 61
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×