Search code examples
pythonpandasdataset

When reading dataset with pandas it shows that the columns are shifted all one to the right and therefore the values do not align


When reading my dataset in pandas and displaying the dataset I can see that every column is shifted one to the right which makes all the values belonging to the wrong column.

import pandas as pd
import csv
pd.read_csv("ACLED.csv", on_bad_lines='skip', delimiter=";", quoting=csv.QUOTE_NONE)
pd.head()

The image I included shows that normally the first column event_id_cnty should be one to the left like all other columns and be over ARG13046.Image dataset


Solution

  • You need to use index_col=False as a kwarg in pd.read_csv(...). This will ensure that the id column will not become the index, which is currently causing all column names to shift to the right. Here is the full documentation.

    pd.read_csv("ACLED.csv", on_bad_lines='skip', delimiter=";",
                quoting=csv.QUOTE_NONE, index_col=False)