Python excel Row different rows -


i compare rows 1-3 , rows 9-16 excel spreadsheet. code have right now, know how 1-3, not both 1-3 and 9-16:

with open('weather.csv', 'r') file1:      val = list(csv.reader(file1))[i]      val1 = val[0:3] 

i tried this:

with open('weather.csv', 'r') file1:      val = list(csv.reader(file1))[i]      val1 = val[0:3][9:16] 

but doesn't work; nothing happens.

well without knowing data file contains, i'm going assume each row contains 2 comma separated values (weather, temperature).

so first:

val1 = val[0:3][9:16] not because you're saying slice val list between index 0 , 3 , slice slice starting index of 9 16, won't exist (because sliced 0:3), therefore you'll empty string in return.

if you'd compare multiple rows batching rows together, you'd want along lines of:

compare1 = val[0:3] compare2 = val[9:16] 

and perform whatever 'comparison' level operations you'd there. i'm not sure why you'd though instead of slicing original val value want each desired comparison.

for example, if know: row 1 contains 'new york, 60' , row 12 contains 'san francisco, 75'

and you'd compare temperatures of these cities can run:

val[0][1] < val[11][1] return 'true'


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -