Using datas from a csv file to select data in another csv
up vote
0
down vote
favorite
I am very new to python and I am now stuck.
I am trying to match my field notes with the data file from my device.
I have two files record.csv and workingfile.csv.
columns in record.csv
:
DOE,Plot_ID,type
columns in workingfile.csv
:
JULIAN_DAYS,HP_12CH4,Day_of_exp,HP_13CH4,HP_Delta_iCH4_30s,12CO2,13CO2,CO2_tot,CH4_tot,Delta_30s_iCO2
For each line of record.csv
, I want to select the lines from workingfile.csv
for which Day_of_exp
is contained between DOE
and DOE + measuringtime
. And make a new file with these selected lines and the columns from record.csv
I have a lot of data, reason why I decided to try python for this.
Thank you very much if anyone can help! I tried several things that did not lead to anywhere...
python csv
New contributor
add a comment |
up vote
0
down vote
favorite
I am very new to python and I am now stuck.
I am trying to match my field notes with the data file from my device.
I have two files record.csv and workingfile.csv.
columns in record.csv
:
DOE,Plot_ID,type
columns in workingfile.csv
:
JULIAN_DAYS,HP_12CH4,Day_of_exp,HP_13CH4,HP_Delta_iCH4_30s,12CO2,13CO2,CO2_tot,CH4_tot,Delta_30s_iCO2
For each line of record.csv
, I want to select the lines from workingfile.csv
for which Day_of_exp
is contained between DOE
and DOE + measuringtime
. And make a new file with these selected lines and the columns from record.csv
I have a lot of data, reason why I decided to try python for this.
Thank you very much if anyone can help! I tried several things that did not lead to anywhere...
python csv
New contributor
1
DOE + measuringtime
, what ismeasuringtime
?
– Mayank Porwal
Nov 21 at 12:44
Sorry, missed this. measuringtime is just a value that is added to DOE (DOE is the start of the measurement, DOE+measuringtime is the end of the measurement.
– Lours
Nov 21 at 13:47
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am very new to python and I am now stuck.
I am trying to match my field notes with the data file from my device.
I have two files record.csv and workingfile.csv.
columns in record.csv
:
DOE,Plot_ID,type
columns in workingfile.csv
:
JULIAN_DAYS,HP_12CH4,Day_of_exp,HP_13CH4,HP_Delta_iCH4_30s,12CO2,13CO2,CO2_tot,CH4_tot,Delta_30s_iCO2
For each line of record.csv
, I want to select the lines from workingfile.csv
for which Day_of_exp
is contained between DOE
and DOE + measuringtime
. And make a new file with these selected lines and the columns from record.csv
I have a lot of data, reason why I decided to try python for this.
Thank you very much if anyone can help! I tried several things that did not lead to anywhere...
python csv
New contributor
I am very new to python and I am now stuck.
I am trying to match my field notes with the data file from my device.
I have two files record.csv and workingfile.csv.
columns in record.csv
:
DOE,Plot_ID,type
columns in workingfile.csv
:
JULIAN_DAYS,HP_12CH4,Day_of_exp,HP_13CH4,HP_Delta_iCH4_30s,12CO2,13CO2,CO2_tot,CH4_tot,Delta_30s_iCO2
For each line of record.csv
, I want to select the lines from workingfile.csv
for which Day_of_exp
is contained between DOE
and DOE + measuringtime
. And make a new file with these selected lines and the columns from record.csv
I have a lot of data, reason why I decided to try python for this.
Thank you very much if anyone can help! I tried several things that did not lead to anywhere...
python csv
python csv
New contributor
New contributor
edited Nov 21 at 13:05
Ali AzG
532414
532414
New contributor
asked Nov 21 at 12:40
Lours
1
1
New contributor
New contributor
1
DOE + measuringtime
, what ismeasuringtime
?
– Mayank Porwal
Nov 21 at 12:44
Sorry, missed this. measuringtime is just a value that is added to DOE (DOE is the start of the measurement, DOE+measuringtime is the end of the measurement.
– Lours
Nov 21 at 13:47
add a comment |
1
DOE + measuringtime
, what ismeasuringtime
?
– Mayank Porwal
Nov 21 at 12:44
Sorry, missed this. measuringtime is just a value that is added to DOE (DOE is the start of the measurement, DOE+measuringtime is the end of the measurement.
– Lours
Nov 21 at 13:47
1
1
DOE + measuringtime
, what is measuringtime
?– Mayank Porwal
Nov 21 at 12:44
DOE + measuringtime
, what is measuringtime
?– Mayank Porwal
Nov 21 at 12:44
Sorry, missed this. measuringtime is just a value that is added to DOE (DOE is the start of the measurement, DOE+measuringtime is the end of the measurement.
– Lours
Nov 21 at 13:47
Sorry, missed this. measuringtime is just a value that is added to DOE (DOE is the start of the measurement, DOE+measuringtime is the end of the measurement.
– Lours
Nov 21 at 13:47
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
I don't understand what is measuringtime, but you can try with:
import csv
f1 = open("record.csv", "r")
reader = csv.DictReader(f1, delimiter='t') #DictReader let you read the csv header
f2 = open("workingfile.csv", "r")
reader2 = csv.DictReader(f2, delimiter='t')
f3 = csv.writer(open("newfile.csv", "w"))
record = #create a list to append values from first file
workingfile = #create a list to append values from second file
for row in reader:
record.append(row['DOE']) #take values from DOE column
print(values)
for row in reader2:
workingfile.append(row['Day_of_exp']) #take values from Day_of_exp column
print(values2)
for v in workingfile:
if v in record:
f3.writerow([v])
print(v)
f1.close()
f2.close()
This works to compare two columns in different csv.
add a comment |
up vote
0
down vote
Well, I managed to do something! I share it here just in case. It is probably not the best way to do it, feel free to criticise.
working_file = "workingfile.csv"
record_file = "record.csv"
output = "output.csv"
measure_t = 0.004167 #in days, 0.004167 day corresponds to a 6 minutes measurement
out = csv.writer(open(output, "w"))
out.writerow(["DOE", "Plot_ID", "type", "CO2", "CH4"])
data1 = pd.read_csv(working_file)
data2 = pd.read_csv(record_file)
DOE1 = data1.Day_of_exp.tolist()
DOE2 = data2.DOE.tolist()
ID = data2.Plot_ID.tolist()
typ = data2.type.tolist()
CO2 = data1.CO2_tot.tolist()
CH4 = data1.CH4_tot.tolist()
for x in DOE2:
for v in DOE1:
if x <= v <= x + measure_t:
n = DOE2.index(x)
y = ID[n]
z = typ[n]
co2 = CO2[n]
ch4 = CH4[n]
out.writerow((v,y,z,co2,ch4))
Cheers!
New contributor
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
I don't understand what is measuringtime, but you can try with:
import csv
f1 = open("record.csv", "r")
reader = csv.DictReader(f1, delimiter='t') #DictReader let you read the csv header
f2 = open("workingfile.csv", "r")
reader2 = csv.DictReader(f2, delimiter='t')
f3 = csv.writer(open("newfile.csv", "w"))
record = #create a list to append values from first file
workingfile = #create a list to append values from second file
for row in reader:
record.append(row['DOE']) #take values from DOE column
print(values)
for row in reader2:
workingfile.append(row['Day_of_exp']) #take values from Day_of_exp column
print(values2)
for v in workingfile:
if v in record:
f3.writerow([v])
print(v)
f1.close()
f2.close()
This works to compare two columns in different csv.
add a comment |
up vote
0
down vote
I don't understand what is measuringtime, but you can try with:
import csv
f1 = open("record.csv", "r")
reader = csv.DictReader(f1, delimiter='t') #DictReader let you read the csv header
f2 = open("workingfile.csv", "r")
reader2 = csv.DictReader(f2, delimiter='t')
f3 = csv.writer(open("newfile.csv", "w"))
record = #create a list to append values from first file
workingfile = #create a list to append values from second file
for row in reader:
record.append(row['DOE']) #take values from DOE column
print(values)
for row in reader2:
workingfile.append(row['Day_of_exp']) #take values from Day_of_exp column
print(values2)
for v in workingfile:
if v in record:
f3.writerow([v])
print(v)
f1.close()
f2.close()
This works to compare two columns in different csv.
add a comment |
up vote
0
down vote
up vote
0
down vote
I don't understand what is measuringtime, but you can try with:
import csv
f1 = open("record.csv", "r")
reader = csv.DictReader(f1, delimiter='t') #DictReader let you read the csv header
f2 = open("workingfile.csv", "r")
reader2 = csv.DictReader(f2, delimiter='t')
f3 = csv.writer(open("newfile.csv", "w"))
record = #create a list to append values from first file
workingfile = #create a list to append values from second file
for row in reader:
record.append(row['DOE']) #take values from DOE column
print(values)
for row in reader2:
workingfile.append(row['Day_of_exp']) #take values from Day_of_exp column
print(values2)
for v in workingfile:
if v in record:
f3.writerow([v])
print(v)
f1.close()
f2.close()
This works to compare two columns in different csv.
I don't understand what is measuringtime, but you can try with:
import csv
f1 = open("record.csv", "r")
reader = csv.DictReader(f1, delimiter='t') #DictReader let you read the csv header
f2 = open("workingfile.csv", "r")
reader2 = csv.DictReader(f2, delimiter='t')
f3 = csv.writer(open("newfile.csv", "w"))
record = #create a list to append values from first file
workingfile = #create a list to append values from second file
for row in reader:
record.append(row['DOE']) #take values from DOE column
print(values)
for row in reader2:
workingfile.append(row['Day_of_exp']) #take values from Day_of_exp column
print(values2)
for v in workingfile:
if v in record:
f3.writerow([v])
print(v)
f1.close()
f2.close()
This works to compare two columns in different csv.
answered Nov 21 at 13:17
Lara M.
396317
396317
add a comment |
add a comment |
up vote
0
down vote
Well, I managed to do something! I share it here just in case. It is probably not the best way to do it, feel free to criticise.
working_file = "workingfile.csv"
record_file = "record.csv"
output = "output.csv"
measure_t = 0.004167 #in days, 0.004167 day corresponds to a 6 minutes measurement
out = csv.writer(open(output, "w"))
out.writerow(["DOE", "Plot_ID", "type", "CO2", "CH4"])
data1 = pd.read_csv(working_file)
data2 = pd.read_csv(record_file)
DOE1 = data1.Day_of_exp.tolist()
DOE2 = data2.DOE.tolist()
ID = data2.Plot_ID.tolist()
typ = data2.type.tolist()
CO2 = data1.CO2_tot.tolist()
CH4 = data1.CH4_tot.tolist()
for x in DOE2:
for v in DOE1:
if x <= v <= x + measure_t:
n = DOE2.index(x)
y = ID[n]
z = typ[n]
co2 = CO2[n]
ch4 = CH4[n]
out.writerow((v,y,z,co2,ch4))
Cheers!
New contributor
add a comment |
up vote
0
down vote
Well, I managed to do something! I share it here just in case. It is probably not the best way to do it, feel free to criticise.
working_file = "workingfile.csv"
record_file = "record.csv"
output = "output.csv"
measure_t = 0.004167 #in days, 0.004167 day corresponds to a 6 minutes measurement
out = csv.writer(open(output, "w"))
out.writerow(["DOE", "Plot_ID", "type", "CO2", "CH4"])
data1 = pd.read_csv(working_file)
data2 = pd.read_csv(record_file)
DOE1 = data1.Day_of_exp.tolist()
DOE2 = data2.DOE.tolist()
ID = data2.Plot_ID.tolist()
typ = data2.type.tolist()
CO2 = data1.CO2_tot.tolist()
CH4 = data1.CH4_tot.tolist()
for x in DOE2:
for v in DOE1:
if x <= v <= x + measure_t:
n = DOE2.index(x)
y = ID[n]
z = typ[n]
co2 = CO2[n]
ch4 = CH4[n]
out.writerow((v,y,z,co2,ch4))
Cheers!
New contributor
add a comment |
up vote
0
down vote
up vote
0
down vote
Well, I managed to do something! I share it here just in case. It is probably not the best way to do it, feel free to criticise.
working_file = "workingfile.csv"
record_file = "record.csv"
output = "output.csv"
measure_t = 0.004167 #in days, 0.004167 day corresponds to a 6 minutes measurement
out = csv.writer(open(output, "w"))
out.writerow(["DOE", "Plot_ID", "type", "CO2", "CH4"])
data1 = pd.read_csv(working_file)
data2 = pd.read_csv(record_file)
DOE1 = data1.Day_of_exp.tolist()
DOE2 = data2.DOE.tolist()
ID = data2.Plot_ID.tolist()
typ = data2.type.tolist()
CO2 = data1.CO2_tot.tolist()
CH4 = data1.CH4_tot.tolist()
for x in DOE2:
for v in DOE1:
if x <= v <= x + measure_t:
n = DOE2.index(x)
y = ID[n]
z = typ[n]
co2 = CO2[n]
ch4 = CH4[n]
out.writerow((v,y,z,co2,ch4))
Cheers!
New contributor
Well, I managed to do something! I share it here just in case. It is probably not the best way to do it, feel free to criticise.
working_file = "workingfile.csv"
record_file = "record.csv"
output = "output.csv"
measure_t = 0.004167 #in days, 0.004167 day corresponds to a 6 minutes measurement
out = csv.writer(open(output, "w"))
out.writerow(["DOE", "Plot_ID", "type", "CO2", "CH4"])
data1 = pd.read_csv(working_file)
data2 = pd.read_csv(record_file)
DOE1 = data1.Day_of_exp.tolist()
DOE2 = data2.DOE.tolist()
ID = data2.Plot_ID.tolist()
typ = data2.type.tolist()
CO2 = data1.CO2_tot.tolist()
CH4 = data1.CH4_tot.tolist()
for x in DOE2:
for v in DOE1:
if x <= v <= x + measure_t:
n = DOE2.index(x)
y = ID[n]
z = typ[n]
co2 = CO2[n]
ch4 = CH4[n]
out.writerow((v,y,z,co2,ch4))
Cheers!
New contributor
New contributor
answered Nov 21 at 17:10
Lours
1
1
New contributor
New contributor
add a comment |
add a comment |
Lours is a new contributor. Be nice, and check out our Code of Conduct.
Lours is a new contributor. Be nice, and check out our Code of Conduct.
Lours is a new contributor. Be nice, and check out our Code of Conduct.
Lours is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53412246%2fusing-datas-from-a-csv-file-to-select-data-in-another-csv%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
DOE + measuringtime
, what ismeasuringtime
?– Mayank Porwal
Nov 21 at 12:44
Sorry, missed this. measuringtime is just a value that is added to DOE (DOE is the start of the measurement, DOE+measuringtime is the end of the measurement.
– Lours
Nov 21 at 13:47