मराठी

Which of the following Python commands selects the first 3 rows of a DataFrame df, assuming that labelled index are consecutive integers starting from 0? - Informatics Practices

Advertisements
Advertisements

प्रश्न

Which of the following Python commands selects the first 3 rows of a DataFrame df, assuming that labelled index are consecutive integers starting from 0?

पर्याय

  • df.loc[:3]

  • df.loc[:2]

  • df.loc[0:4]

  • df.loc[1:4]

MCQ
Advertisements

उत्तर

df.loc[:2]

Explanation:

In pandas, .loc[] selects rows by label and includes the end label.
Since the index starts at 0, the first three rows have labels 0, 1, and 2.
So df.loc[:2] correctly selects these three rows (0, 1, and 2).

shaalaa.com
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
2025-2026 (March) Board Sample Paper
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×