Please assist me with this for loop with Excel rows ranges | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Please assist me with this for loop with Excel rows ranges

I'm trying to make the for loop add ranges of 20 rows each from an Excel file to a list one range at a time, and then move to the next range of 20 until the file is complete (800+ rows): 1-20, 21-41, 42-62, etc. Any ideas, please? https://code.sololearn.com/cQ88nsxzbHGH/?ref=app

25th May 2020, 5:08 PM
Jairo Arce Hernandez
Jairo Arce Hernandez - avatar
13 Answers
+ 5
As csv files can have column headers or various quotes and separators, it would be great if you could include the your csv file in the code. Put the content in triple qotes (doc string). Thanks!
25th May 2020, 5:32 PM
Lothar
Lothar - avatar
+ 5
Jairo, i have the feeling, that i still miss some information to get a clear picture. Here some more questions from me. I am not sure if we really need pandas. (1) The questions you bundle in a list and then send to the API, are they in the sequence as they are in the file? (2) What about the answers? Do you need them for your project? My idea was, to use the python csv module, read the file with an generator, and then create the bundle of 20 questions to send to the API.
26th May 2020, 8:18 AM
Lothar
Lothar - avatar
+ 4
No you should not attach the file. Just do copy the first 3 lines and past them in the playground file with your code. So we are able to create the sample file for our local system to do a test for you. Thanks
25th May 2020, 5:49 PM
Lothar
Lothar - avatar
+ 4
Jairo, Column B: Row 2: 'Answer' Row 3: 'They are...' Row 3: 'All ...' Shouldn't it be like this: Column B: Row 1: 'Answer' Row 2: 'They are...' Row 3: 'All ...' And: how are the 2 columns in a line separated? By comma, semicolon, space,... ?
25th May 2020, 6:16 PM
Lothar
Lothar - avatar
+ 4
Line 25 and 29 creates an error message: Index not found Can you tell us what you are going to achieve? How should your output look like?
25th May 2020, 7:31 PM
Lothar
Lothar - avatar
+ 4
Here is a try how to read from the csv without pandas. https://code.sololearn.com/cSW124e0HT2k/?ref=app
26th May 2020, 5:08 PM
Lothar
Lothar - avatar
+ 1
Check through the error in the code¿ it says that there is no file like Pd intersight QA.csv
25th May 2020, 5:15 PM
Isaac Duah [Active!]
Isaac Duah [Active!] - avatar
+ 1
Thank you Lothar!
26th May 2020, 9:22 PM
Jairo Arce Hernandez
Jairo Arce Hernandez - avatar
0
Thanks for your reply, Issac. So the file is saved locally in my laptop. I don't think there's a way to attach files to this posts though
25th May 2020, 5:35 PM
Jairo Arce Hernandez
Jairo Arce Hernandez - avatar
0
Thank you Lothar, I have modified the code in the playground as you advised. TIA for any possible suggestions
25th May 2020, 6:05 PM
Jairo Arce Hernandez
Jairo Arce Hernandez - avatar
0
By comma (comma delimited)
25th May 2020, 6:19 PM
Jairo Arce Hernandez
Jairo Arce Hernandez - avatar
0
The overall project is about sending the 800+ questions to an API so it returns vectors for each question. For this, I need to send batches of 20 questions at a time to not overburden the API. This why I need the loop to create lists containing 20 questions each from the file. My output from the first 20 questions looks like this: ['Does the Cisco Intersight only permit the use of shared/group accounts for maintenance and management of information systems?', 'Does the Cisco Intersight document the allowed methods of remote access?', 'Does Cisco Intersight authorize, manage and monitor all methods of remote access to the system?', 'Does Cisco Intersight monitor events?', etc..]
25th May 2020, 7:51 PM
Jairo Arce Hernandez
Jairo Arce Hernandez - avatar
0
1) it's not mandatory for the questions to be in the same sequence as in the file but it's preferred. 2) I do not need the answers for my project actually That's an interesting idea
26th May 2020, 1:22 PM
Jairo Arce Hernandez
Jairo Arce Hernandez - avatar