Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 30th, 2012, 01:25 PM
123456789876543 123456789876543 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 2 123456789876543 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 24 m 14 sec
Reputation Power: 0
Beginner at python, need help

I have a program that reads a CSV file. It currently looks like this. The CSV file is NFL Football stats. The names of the rows of the CSV are Name, Games, Receptions, Receiving Yards, etc.



import csv

players = {}

with open('NFL 2011 reassembled.csv', 'rU') as csvfile:
spamreader = csv.DictReader(csvfile, delimiter=',', quotechar='|')
for row in spamreader:
players[row['Name'].strip()] = row



The numbers are strings now, so I cannot change them. How can I change them into integers?
Thanks. I am a beginner to Python, so any help would be greatly appreciated.

Reply With Quote
  #2  
Old December 30th, 2012, 03:50 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,380 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 13 h 7 m 19 sec
Reputation Power: 383
Use int

>>> print(7*int('4'))
28
__________________
[code]Code tags[/code] are essential for python code!

Reply With Quote
  #3  
Old December 30th, 2012, 11:18 PM
123456789876543 123456789876543 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 2 123456789876543 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 24 m 14 sec
Reputation Power: 0
That won't work because I want to be able to put any row of the CSV file in there. Is there something I could do that would look something like:

int(players['Games')
#players is the name of the csv file
Or something that would turn it into an integer?
thanks

Reply With Quote
  #4  
Old December 31st, 2012, 01:11 AM
Sachin Bali Sachin Bali is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 9 Sachin Bali User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 42 m 30 sec
Reputation Power: 0
[QUOTE=123456789876543]That won't work because I want to


>>> a = "545.2222"
>>> float(a)
545.22220000000004
>>> int(float(a))
545


Try this. If still not working, please get back.

Regards,
Sachin Bali

Reply With Quote
  #5  
Old December 31st, 2012, 07:28 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,380 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 13 h 7 m 19 sec
Reputation Power: 383
If you provide a few lines of the input and also show what you want for output, and perhaps a formula (in some sort of reasonable descriptive language) that computes the output from the input, you might thereby get some useful assistance.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Beginner at python, need help

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap