-3

following is a preview of a marketing dataframe. Complete the code to get desired output

   id  views  clicks
a  1   1000   300
b  2   1200   800
c  3   800    200

output

   views  clicks
a  1000   300

what should i change in my code to get this output

import pandas as pd
market=pd.read_csv("marketing.csv")
print(market.iloc[0])
3
  • What output u get now.? Commented Sep 1, 2018 at 8:00
  • i get first row as my output with column names Commented Sep 1, 2018 at 8:04
  • no all the columns are named in that Commented Sep 1, 2018 at 8:32

1 Answer 1

1

You can use iloc like this for your purpose. But you will get a Series

market.iloc[[0], [1, 2]]

or loc like this to get a dataframe

market.loc[['a'], ['views', 'clicks']]
Sign up to request clarification or add additional context in comments.

6 Comments

iloc is not printing a
loc command is showing an error
@Ayushimidha You need to pass a list of rows for it to show a DataFrame instead of a Series. See the edit.
loc is still showing error
iloc command is giving the desired output
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.