Sample Header Ad - 728x90

Loop over columns and store values to associative arrays

0 votes
2 answers
7729 views
I've got a text file containing two columns, like so: 26 0.000342231 27 0.000342231 28 0.000684463 29 0.00136893 30 0.00102669 31 0.00308008 32 0.00308008 33 0.00444901 34 0.00718686 35 0.00718686 36 0.0109514 37 0.0123203 ... I'd like to loop over the text file and store each columns value to an associative array - something like a dictionary. If possible I'd like to keep data types of values in each column (int and float). For a calculation I then need to sum up 2nd column's values for a particular interval till the end of the file, e.g. "sum up 29's (1st column) associated value (0.00136893) down to the last associated value" What's the best way to do so? Bash and python solutions are most welcome!
Asked by Aliakbar Ahmadi (203 rep)
Aug 11, 2015, 10:18 AM
Last activity: Apr 20, 2024, 03:09 PM