I have an excel file and I want to read each column and create separate lists for them. I want to then compare each element of each list with other corresponding lists I have.
Is there a way I can convert the columns into lists using python?
for eg(i can get this file as a txt space separated file or an excel file)
HST_9578_02_ACS_WFC_F775W 245.8976441 -26.5255957 4339.570 1882.364
HST_10615_03_ACS_WFC_F435W 245.8976450 -26.5255138 2084.978 2101.122
HST_10120_02_ACS_WFC_F658N 245.8976758 -26.5255024 1778.055 1752.193
HST_10775_64_ACS_WFC_F606W 245.8977532 -26.5255296 2586.612 2603.519
HST_10775_64_ACS_WFC_F814W 245.8977532 -26.5255296 2586.612 2603.519
HST_9578_02_ACS_WFC_F775W 245.8978148 -26.5255491 4328.571 1885.712
HST_10120_02_ACS_WFC_F625W 245.8978053 -26.5254741 1769.711 1754.229
HST_10353_02_ACS_WFC_F435W 245.8976003 -26.5257784 3758.430 985.125
HST_10775_64_ACS_WFC_F606W 245.8979115 -26.5254936 2576.410 2606.114
This sounds like a job for Python’s CSV module. Each row read is returned as a list of strings.
To borrow a short example from the documentation:
[this simply prints out each row]
You could get to specific columns by indexing into the rows with the index values as appropriate.
Or if you want to do this “manually” (each row is separated by a
,):gives:
EDIT/UPDATE:
To combine the two approaches into one:
The advantage of using
withto open the file is that it will be automatically closed for you when you are done or if an exception occurs.