Created
March 12, 2017 22:51
-
-
Save SyntheticDream/e7cb3b151603dfb335cd98a5093a023a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python3 | |
def round_volts(num, precision=4): | |
return round(to_float(num), precision) # -- too slow | |
# cut = precision+2 | |
# if num[0] == '-': | |
# cut += 1 | |
# return num[:cut] | |
def to_float(num): | |
return float(num.replace(',', '.')) | |
def from_float(num): | |
return str(num).replace('.', ',') | |
def read_files(names): | |
all_raw_data = [] | |
for name in names: | |
with open(name) as f: | |
raw_data = f.read() | |
all_raw_data.append(raw_data.splitlines()) | |
return all_raw_data | |
names = ['data1.csv', 'data2.csv'] | |
raw_data1, raw_data2 = read_files(names) | |
with open('output.csv', mode='w') as f: | |
for data1 in raw_data1: | |
volt1, amp1 = data1.split(';') | |
rounded_volt1 = round_volts(volt1) | |
for data2 in raw_data2: | |
volt2, amp2 = data2.split(';') | |
rounded_volt2 = round_volts(volt2) | |
if rounded_volt1 == rounded_volt2: | |
row = '{};{}\n'.format(volt1, from_float(to_float(amp1)/to_float(amp2))) | |
#print(row[:-1]) | |
f.write(row) | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment