Informatics Practices
Write code statements to list the following, from a 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.
Python Pandas
8 Likes
Answer
(a)
>>> sales[['Item', 'Revenue']]
(b)
>>> sales.iloc[2:7]
(c)
>>> sales.Item[4]
Answered By
3 Likes
Related Questions
Consider two objects x and y. x is a list whereas y is a Series. Both have values 20, 40, 90, 110.
What will be the output of the following two statements considering that the above objects have been created already ?
(a) print (x*2)
(b) print (y*2)
Justify your answer.
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 statements ?
(a) df['C'] = np.NaN
(b) df['C'] = [2, 5]
(c) df['C'] = [12, 15, 27]
Hitesh wants to display the last four rows of the dataframe df and has written the following code :
df.tail()But last 5 rows are being displayed. Identify the error and rewrite the correct code so that last 4 rows get displayed.
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.