Sumita Arora Solution

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.

Ans:(a)del df[<columnname>](b)df.drop(range(3,7))(c)df.isnull().values.any()(d)df.fillna(999, inplace = True)

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. Read More »

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.

Ans:to add a new column ‘val’ in dataframe ‘df’ we will write-df[‘val’]=[12,23,45,43,55,12,23,43,11,29]Here we are assigning 10 different values to ‘val’ column as df have 10 rows.

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. Read More »

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.

Ans:(a)print(df[[‘Item’,’revenue’]) (b)print(df.loc(3:8)) (c)print(df.Item[5])

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. Read More »

error: Content is protected !!