Wednesday, October 3, 2018

Python Combine and Write Multiple Separate CSV Files Together


This code combines positive and negative training, testing data for performing binary classification machine learning.

Code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
import pandas as pd

train_positive_data = pd.read_csv('csv_files/trainPositive.csv', header=None)
train_negative_data = pd.read_csv('csv_files/trainNegative.csv', header=None)

test_positive_data = pd.read_csv('csv_files/testPositive.csv', header=None)
test_negative_data = pd.read_csv('csv_files/testNegative.csv', header=None)



train_output = train_negative_data.append(train_positive_data)
test_output = test_negative_data.append(test_positive_data)



output_train_name = "csv_files/trainCombined.csv"
train_output.to_csv(output_train_name, index=False, header=False)

output_test_name = "csv_files/testCombined.csv"
test_output.to_csv(output_test_name, index=False, header=False)

No comments: