English

Can you write the command to load the data.txt including the header row as well?

Advertisements
Advertisements

Question

Can you write the command to load the data.txt including the header row as well?

Code Writing
Advertisements

Solution

To load the data from data.txt including the header row, we can use the loadtxt() function of NumPy with the skiprows option set to 0.

import numpy as np
data = np.loadtxt('data.txt', dtype=str, delimiter=',', skiprows=0)
print(data)

Here, skiprows=0 means that no row is skipped, so the header row is also included while loading the data.

shaalaa.com
  Is there an error in this question or solution?
Chapter 6: Introduction to NumPy - Intext Questions [Page 111]

APPEARS IN

NCERT Informatics Practices [English] Class 11
Chapter 6 Introduction to NumPy
Intext Questions | Q 2. | Page 111
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×