-1

Hi I have some data in csv format.

I have some very simple code that is just meant to remove the first row:

import numpy as np
import pandas as pd
data = pd.read_csv("mydata.csv")
data = data.drop(data.columns[[0]],axis=0)
data.to_csv("mydata2.csv")

However when run, I receieve this error:

Warning (from warnings module):
  File "C:/Users/george/Desktop/testing/output/PIVOTING.py", line 1
DtypeWarning: Columns (6) have mixed types. Specify dtype option on import or set low_memory=False.

Traceback (most recent call last):
  File "C:/Users/george/Desktop/testing/output/PIVOTING.py", line 5, in <module>
    data = data.drop(data.columns[[0]],axis=0)
  File "C:\Python27\lib\site-packages\pandas\core\frame.py", line 3697, in drop
    errors=errors)
  File "C:\Python27\lib\site-packages\pandas\core\generic.py", line 3111, in drop
    obj = obj._drop_axis(labels, axis, level=level, errors=errors)
  File "C:\Python27\lib\site-packages\pandas\core\generic.py", line 3143, in _drop_axis
    new_axis = axis.drop(labels, errors=errors)
  File "C:\Python27\lib\site-packages\pandas\core\indexes\base.py", line 4404, in drop
    '{} not found in axis'.format(labels[mask]))
KeyError: "['C'] not found in axis"
user8261831
  • 464
  • 1
  • 4
  • 20

1 Answers1

1

For future reference, pandas read_csv accept skiprows to help achieve exatly that task, as covered extensively here

Jacopo Repossi
  • 375
  • 2
  • 10