-1

I'm trying to read in a text file with two columns, in numpy/pandas.

I get an error on both columns, Member_ID, Home_ownership, however, after adding delimiter=',', the issue disappears for Home_ownership column.

Here's my code. Based on online videos I tried adding encoder='latin', but it didn't work.

import numpy as np
import matplotlib.pyplot as plt 
import pandas as pd

home_ownership = np.loadtxt(r'C:\Users\Shlesha13\Desktop\mais-202-coding-challenge-f2019-master\home_ownership_data.csv', delimiter=',')
print (home_ownership)
smci
  • 32,567
  • 20
  • 113
  • 146
  • 1
    Please provide a traceback. – pppery Sep 13 '19 at 01:37
  • whats the csv file look like..whats in it – Derek Eden Sep 13 '19 at 01:37
  • Hey, here is the link to csv file: https://drive.google.com/file/d/1TLoze56FhyQoIMkC6Pvz9m-AsVe5cbX_/view?usp=sharing – Shlesha Van Sep 13 '19 at 01:55
  • Welcome to SO. Please be sure to state your issue clearly ("reading in a text (CSV) file with two columns"); also to tag clearly (this should have been tagged 'pandas' and has nothing to do with Spyder, Spyder is only the IDE, it doesn't cause errors) – smci Sep 16 '19 at 20:16

1 Answers1

2

You can read your CSV using numpy or using pandas.

import numpy as np
# import matplotlib.pyplot as plt 
import pandas as pd

path = 'home_ownership_data.csv'
arr = np.genfromtxt(path, delimiter=',', dtype=None)
df = pd.read_csv(path)
print(df)
print(arr)
  • Hey, I just tried, didn't affect the result. tried placing it both before and after calling the file. any other thoughts? – Shlesha Van Sep 13 '19 at 02:43
  • Ah, it's because your 2nd column has string values. Let me edit my answer. –  Sep 13 '19 at 03:16