Home > front end >  CSV Imported with column merged
CSV Imported with column merged

Time:09-24

I am new to python, trying to do a school assignment I tried to upload my CSV into python

import pandas as pd
import sqlite3
from pandas.io import sql

BANK_FULL = pd.read_csv('../csv/bank-full.csv', encoding = 'utf-8')
print(BANK_FULL.columns)

Output

Index(['age;"job";"marital";"education";"default";"balance";"housing";"loan";"contact";"day";"month";"duration";"campaign";"pdays";"previous";"poutcome";"y"'], dtype='object')

example

This ends up showing all into 1 column, I know right now they are double quoted therefore shown as 1 column. How can I change the double quote into normal quote so that my columns will show nicely?

Example of text from csv

age job marital education default balance housing loan contact day month duration campaign pdays previous poutcome y

58 management married tertiary no 2143 yes no unknown 5 may 261 1 -1 0 unknown no

44 technician single secondary no 29 yes no unknown 5 may 151 1 -1 0 unknown no

33 entrepreneur married secondary no 2 yes yes unknown 5 may 76 1 -1 0 unknown no

CodePudding user response:

You need to define the delimiter as semicolon. Your code should be like:

import pandas as pd

BANK_FULL = pd.read_csv('../csv/bank-full.csv', encoding='utf-8', delimiter=";")
print(BANK_FULL.columns)

which results in:

Index(['age', 'job', 'marital', 'education', 'default', 'balance', 'housing',
       'loan', 'contact', 'day', 'month', 'duration', 'campaign', 'pdays',
       'previous', 'poutcome', 'y'],
      dtype='object')
  • Related