Not homework. Wish I was back in school. I have a New Years resolution to learn Python and use it at work whenever I can. I deal with very large data sets and often the records exceed the 1M mark to use in Excel. Any suggestions would be appreciated.
Here is the code I wrote. Yes it's poor I know.
f = open("pricelist.txt", "r")
SSPList = {}
for line in f:
entry = line.strip().split(",")
PartNo = entry[0]
Price = entry[1]
AvgPrice = sum(Price)/len(SSPlist)
f.close()
print(SSPList)
and here is my error message:
Traceback (most recent call last):
File "C:/Python34/Scripts/SSPTest.py", line 8, in <module>
Price = entry[1]
IndexError: list index out of range
Ok, so I messed with it a little more, but I struggle with how to calculate the average. Here is my new code and error message:
f = open("pricelist.csv", "r")
SSPList = {}
for line in f:
entry = line.strip().split(",")
PartNo = entry[0]
print(PartNo)
Price = entry[1]
print(Price)
AvgPrice = sum(Price)/len(SSPlist)
SSPList[PartNo] = AvgPrice
f.close()
print(SSPList)
Error message:
>>>
A
10
Traceback (most recent call last):
File "C:\Python34\Scripts\SSPTest.py", line 11, in <module>
AvgPrice = sum(Price)/len(SSPlist)
TypeError: unsupported operand type(s) for +: 'int' and 'str'
>>>
Here is the code I wrote. Yes it's poor I know.
f = open("pricelist.txt", "r")
SSPList = {}
for line in f:
entry = line.strip().split(",")
PartNo = entry[0]
Price = entry[1]
AvgPrice = sum(Price)/len(SSPlist)
f.close()
print(SSPList)
and here is my error message:
Traceback (most recent call last):
File "C:/Python34/Scripts/SSPTest.py", line 8, in <module>
Price = entry[1]
IndexError: list index out of range
Ok, so I messed with it a little more, but I struggle with how to calculate the average. Here is my new code and error message:
f = open("pricelist.csv", "r")
SSPList = {}
for line in f:
entry = line.strip().split(",")
PartNo = entry[0]
print(PartNo)
Price = entry[1]
print(Price)
AvgPrice = sum(Price)/len(SSPlist)
SSPList[PartNo] = AvgPrice
f.close()
print(SSPList)
Error message:
>>>
A
10
Traceback (most recent call last):
File "C:\Python34\Scripts\SSPTest.py", line 11, in <module>
AvgPrice = sum(Price)/len(SSPlist)
TypeError: unsupported operand type(s) for +: 'int' and 'str'
>>>