0

I am a newbie in Python.

Say I have the following very simple table saved in a text file:

one two three
four five six
seven eight nine

I can view this table using pandas:

import pandas as pd

df = pd.read_csv('table.txt')
print(df)

The outcome of this is:

      one two three
0     four five six
1  seven eight nine

Now, I want to delete the first row (i.e. one two three). My first thought was to write:

df.drop([0])

Because rows and columns are numbered starting from 0. But what this does is that it drops the second row (i.e. four five six).

Thus the title of this question. How to remove a row that has no index number? Because as seen from print(df), the first row is not given an index.

I did try to Google this, but I was not able to find an answer. This is probably because I do not know some keywords.

Aziz
  • 91
  • 2
  • 9
  • 4
    The first row is interpreted as a header. Use `read_csv("table.txt", header=None)` and drop the first row. – Chris Aug 28 '20 at 05:39
  • Does this answer your question? [How are iloc and loc different?](https://stackoverflow.com/questions/31593201/how-are-iloc-and-loc-different) – Let's try Aug 28 '20 at 07:56

1 Answers1

1

One Two Three is the header of CSV file. So to skip it, write the code mentioned below:

df = pd.read_csv('table.txt', header=none)

Ankit Singh
  • 127
  • 2