1

Data

HOD,2012-1-3,1,5000
HOD,2012-1-4,1,5000
HOD,2012-1-5,1,5000
HOD,2012-1-6,1,5000
HOD,2012-1-9,1,5000
HOD,2012-1-10,1,5000

myData = np.genfromtxt(inputFile, dtype=[('Symbol',str),('Date', 'datetime64[D]'),('Value', int),('Allocation', long)], delimiter=',')
print myData

Output

('', datetime.datetime(1969, 12, 31, 0, 0), 1, 5000L)
('', datetime.datetime(1969, 12, 31, 0, 0), 1, 5000L)
('', datetime.datetime(1969, 12, 31, 0, 0), 1, 5000L)
('', datetime.datetime(1969, 12, 31, 0, 0), 1, 5000L)
('', datetime.datetime(1969, 12, 31, 0, 0), 1, 5000L)

Why are my strings lost?

1
  • Note that your dates are not being imported correctly, as well :) (Zero padding for the month and day may help...) Commented May 28, 2014 at 17:16

1 Answer 1

1

String dtype require you to specify length:

dtype=[('Symbol', 'S3'), ...]

or

dtype=[('Symbol', (str, 3)), ...]

If you want arbitrary-length string, specify object as a type; it will allow any object to be assigned.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.