Python help

Parsing with Python

Page 1 of 1

14 Replies - 1838 Views - Last Post: 08 May 2010 - 11:17 PM Rate Topic: -----

#1 Guest_Ineedhelp*


Reputation:

Python help

Posted 07 May 2010 - 09:50 PM

Ok I have to make a program to parse excel spreadsheets and pull out data based on input.

Right now I am trying to import the data and extract the portion i want for my first loop


But when i run the program my 2nd array only seems to have the last entry. here is my code, what am i doing wrong

import fileinput

List2 = list()
List3 = list()
areaCode = input('enter Area code    ')

for line in fileinput.input(['C:\Users\joeh\Desktop\PhoneLog.csv']):
    myList2.append(line.split('\n')[0])


for item in List2:
     List3.append(line.split(',')[0])
#    List3.append(line.split(",")[1])
    
print(List2[0])
print(List3[9999])
#print(List3[12])


Is This A Good Question/Topic? 0

Replies To: Python help

#2 Guest_Ineedhelp*


Reputation:

Re: Python help

Posted 07 May 2010 - 09:52 PM

Ok I have to make a program to parse excel spreadsheets and pull out data based on input.

Right now I am trying to import the data and extract the portion i want for my first loop


But when i run the program my 2nd array only seems to have the last entry. here is my code, what am i doing wrong

import fileinput

List2 = list()
List3 = list()
areaCode = input('enter Area code    ')

for line in fileinput.input(['C:\test\test\test\test']):
    List2.append(line.split('\n')[0])


for item in List2:
     List3.append(line.split(',')[0])
#    List3.append(line.split(",")[1])
    
print(List2[0])
print(List3[0])
#print(List3[12])

Was This Post Helpful? 0

#3 Guest_Ineedhelp*


Reputation:

Re: Python help

Posted 07 May 2010 - 09:54 PM

If there is anyone I could chat with through AIM id appreciate the help. I have the general logic down Im just trying to figure out syntax and troubleshoot Thanks
Was This Post Helpful? 0

#4 Guest_Ineedhelp*


Reputation:

Re: Python help

Posted 07 May 2010 - 10:07 PM

The iput I get from my first loop looks like 1,2345567882,2/23/03,26 with my second loop I want to pull out just the 3 digits after the first comma, so in this case 234. my 2nd loop is currently pulling out the number after the comma, but it is only storing the last entry from my first list.
Was This Post Helpful? 0

#5 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Python help

Posted 07 May 2010 - 10:14 PM

Topics merged, please don't create duplicates.

Also, this is a community for learning/helping and we appreciate keeping the communication in the forums so others may learn from the situation as well :)
Was This Post Helpful? 0
  • +
  • -

#6 Guest_Guest*


Reputation:

Re: Python help

Posted 07 May 2010 - 10:16 PM

ya, sorry, I didnt mean to post twice. I understand, I just have a lot of questions. First time coding in python.
Was This Post Helpful? 0

#7 Guest_Ineedhelp*


Reputation:

Re: Python help

Posted 07 May 2010 - 10:24 PM

Ok , so im not sure why that was not working but what I did is this. combined the creation of the two list in the same loop. Now I still need to figure out how to make it only pull the first 3 digits of the 2nd list.

import fileinput

list1 = list()
list2 = list()
areaCode = input('enter Area code    ')

for line in fileinput.input(['C:\Users\joeh\Desktop\PhoneLog.csv']):
    list1.append(line.split('\n')[0])
    list2.append(line.split(',')[1])


#for item in List2:
#     list2.append(line.split(',')[1])

    
print(list1[1])
print(list2[1])
print(list2[23])





out put looks like

enter Area code 6
2,4831511088,2/22/08,26
4831511088
4623437328
Was This Post Helpful? 0

#8 Skaggles  Icon User is offline

  • THE PEN IS MIGHTIER
  • member icon





Reputation: 251
  • View blog
  • Posts: 640
  • Joined: 01-March 09

Re: Python help

Posted 07 May 2010 - 10:26 PM

If you are new to the Python language, I suggest reading through these introduction tutorials:

An Introduction To Python
Learning To Program Python

For more information, there are more great tutorials available here on DIC:

Python Tutorials
Was This Post Helpful? 0
  • +
  • -

#9 Guest_Ineedhelp*


Reputation:

Re: Python help

Posted 07 May 2010 - 10:37 PM

Thanks , ill look through it, Im having a hard time figuring out the loops using arrays apparently.
Was This Post Helpful? 0

#10 Guest_Guest*


Reputation:

Re: Python help

Posted 07 May 2010 - 11:02 PM

Ok, so i need to do 3 things. I need to

1. Find all the entries that have the same area code via user input. I found the loop if value in list: , i think this will accomplish this although i can not seem to get it to work.

2. I need to find each entry that reoccurs more than X times, where X is a user input. for this im thinking the count loop looks good.

3. and lastly I need to find all time over x minutes. this one should be simple. as this column is just comparing a few digits to be equal to or greater than user input.



Do the previously mentioned loops sound appropriate for my task? im going to start working on seeing if I can get them to work properly, so far I cant get the if value in list to work but im not sure if it is because of the the way im importing my data. Any input is appreciated.
Was This Post Helpful? 0

#11 Guest_Guest*


Reputation:

Re: Python help

Posted 07 May 2010 - 11:38 PM

If i have the following loop


[code]
for index, item in enumerate(list1):
if item > minute:


/code]

is there a way for me to specify int he argument list1 what portion of the array to use with a slice , similar to list1.append(line.split(',')[3]) so if i have a entry separated by commas and the last one is the data i want to compare then that is all it looks at? for example I want it so take a array entry that looks like 456,2345432,24 and compare just the 24 to a user input, but if the criteria match I want it to display the full array entry.
Was This Post Helpful? 0

#12 Guest_Guest*


Reputation:

Re: Python help

Posted 08 May 2010 - 03:38 PM

Ok so i got the part working for check minutes with the following code.

for index, item in enumerate(list1):
   if (int(item) > minute):
      print list2[int(index)]




now im working on the area code evaluation. For this i need to eval only the left 3 charaters of a full number ex
1984563388 I need to pull 198 to eval. I saw some syntax that was like (n([0]) or something but I can seem to find it now. Any one have any idea how to accomplish this?
Was This Post Helpful? 0

#13 Guest_Guest*


Reputation:

Re: Python help

Posted 08 May 2010 - 04:15 PM

Ok, I figured it out, Kind of feel like im talking to myself here but at least if someone is having the same questions this will help them.

here is what i did to get only the first 3 digits

(list3[0])[:3], I will change the index to a dynamic var in my loop and this should allow me to compare similarly to my first loop that i used to compare minutes
Was This Post Helpful? 0

#14 Guest_Guest*


Reputation:

Re: Python help

Posted 08 May 2010 - 04:50 PM

how can i find duplicate in an array and count the number of times they are duplicated and store the duplicated item to be out put to the screen, any suggestions appreciated, Thanks
Was This Post Helpful? 0

#15 Guest_Ineedhelp*


Reputation:

Re: Python help

Posted 08 May 2010 - 11:17 PM

Got it working using sort and a loop to walk through the array and count up the amount a item is duplicated , if it reaches the thresh hold it prints that number to the screen, working perfectly. program finished!
Was This Post Helpful? 0

Page 1 of 1