Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analyzing data #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ __pycache__
.vscode
*.csv
query.graphql.webarchive
.DS_Store
78 changes: 78 additions & 0 deletions src/databases/FileExchange/CSVSplitter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Import libraries
import csv
import sys

def writeToCSV(output, fileName):
# Write rows to the CSV file
with open(fileName, "w") as csvFile:

# Setup CSV writer
csvWriter = csv.writer(csvFile)

# Check if we have the column header
if output[0][0] is not "bodyText":
csvWriter.writerow(["bodyText"])

# Write rows to CSV file
csvWriter.writerows(output)

def outputHandler(output):
# Create subfile name
subfileName = fileNamePrefix + str(subfileCounter) + ".csv"

# Output to screen
print(f"[WORKING] Created {subfileName} with {len(output)} rows")

# Writes to CSV file
writeToCSV(output, subfileName)

if __name__ == "__main__":
# Check if there aren't enough arguments given
if len(sys.argv) < 3:
print("[ERROR] Not enough arguments!")

# Gets the file name from the command line
inputFileName = sys.argv[1]

# What to split every file by
numToSplitCSV = int(sys.argv[2])

# Get the prefix of the file name
fileNamePrefix = inputFileName[:-4]

# Set a counter to assist in naming subfiles
subfileCounter = 0

# Open CSV file
with open(inputFileName) as csvFile:
# Setup CSV Reader
csvReader = csv.reader(csvFile)

# Setup text to be written into CSV
output = list()

# Declare/Initialize line counter
count = 0

# Count each number and get each row
for row in csvReader:

# Add to output
if count < numToSplitCSV:
output.append(row)
count = count + 1

# Write to CSV
elif count == numToSplitCSV:
# write to file if at limit
outputHandler(output)

# Reset count and increase subfileCounter
count = 0
subfileCounter = subfileCounter + 1
output = list()

# Write to file if it is empty
outputHandler(output)


3,365 changes: 3,365 additions & 0 deletions src/databases/FileExchange/JavaScript/Sample/JSDataSampleRandom0.csv

Large diffs are not rendered by default.

Loading