0

I'm a major newbie when it comes to Python and programming. I've been working with a small data set of Apple Computer stock prices. Successfully have parsed the data into columns and rows, but have been unable to convert the values into integers. Here's my code:

f = open("aapl_2.csv", "r")
data = f.read()
rows = data.split('\r')
aapl_prices = []
for row in rows:
    split_row = row.split(",")
    aapl_prices.append(split_row)
print(aapl_prices)
print('\n')


full_data = []

for row in rows:
    split_row = row.split(",")
    split_row[1] = int(split_row[1])
    full_data.append(split_row)

Every time I run this I get the follow error: ValueError: invalid literal for int() with base 10: 'Close'.

I've looked everywhere and I'm kind of stumped.

Thanks in advance.

bawgsy
  • 1
  • 1
  • 3
    You are trying to cast the column names to int,use the csv module to read your csv file and skip the header. Also you don't read all the file into memory just read line by line iterating over the file object – Padraic Cunningham Jul 27 '15 at 19:53
  • 2
    http://stackoverflow.com/questions/11349333/when-processing-csv-data-how-do-i-ignore-the-first-line-of-data this is a copy – FirebladeDan Jul 27 '15 at 19:58
  • You want the stock prices converted to integer values? Seems like you'd want `float` or `Decimal` depending on what you intend doing with them... – martineau Jul 27 '15 at 19:58
  • You're trying to typecast a str object('close') to an int type ! – Sentient07 Jul 27 '15 at 19:58
  • Thank you, everyone. I found the error in my ways... – bawgsy Jul 28 '15 at 20:23

0 Answers0