Reputation: 53
I am trying to load a text file that has two columns: the first column is labeled as the "date" and it is a string value (i.e. '12/31/19', '1/1/20', etc.). The second column is a value (integer type) that corresponds to the date.
When I attempt to use np.loadtxt, I get the error:
ValueError: could not convert string to float: '12/31/19'
So I tried to open the file by using Pandas with read_csv. But I ended up getting a table like this. I'm trying to separate the two columns from each other and put the values of each column into two separate arrays. Is there another simple method to open a txt file that has values in string format and place them into a list? Thanks!
Upvotes: 0
Views: 406
Reputation: 1242
From looking at the picture you attached, it looks like your columns are separated by tabs. You need to set the sep argument to "\t" like this:
pandas.read_csv('filename', sep='\t')
# OR
numpy.loadtxt('filename', delimiter='\t')
Upvotes: 2