joel
joel

Reputation: 1186

Issue with index in pandas

I am facing issue while loading data a tab separated file with pandas. It assigns the first columns as index and whole data is shifted to the left. The abstract column as a result has NaN value. If I do reset_index on the dataframe, it will drop the index. How to fix this issue.

data = pd.read_csv(file_path, sep='\t')
data.head()

enter image description here

Adding screenshot of TSV file enter image description here

Upvotes: 1

Views: 379

Answers (2)

Pubudu Sitinamaluwa
Pubudu Sitinamaluwa

Reputation: 978

According to the docs, setting index_col=False when reading the CSV can be used to force pandas to not use the first column as the index.

Reference

Upvotes: 0

Please try the below code...

data = pd.read_csv(file_path, sep='\t')
data.drop(index=0, inplace=True)
data.head()

Upvotes: 1

Related Questions