Created
April 17, 2020 10:39
-
-
Save yogi-bp/a6908cac57934568fdc3799f35f5d012 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
# Dependency - Pandas | |
from os import path | |
import pandas | |
RESOURCE_DIRECTORY = '/home/yogi/byprice/projects/geoprice-services/resources' | |
CLIENT_ID_FILENAME = 'mapping.txt' | |
def get_client_mapping(): | |
client_name_id = {} | |
with open(path.join(RESOURCE_DIRECTORY, CLIENT_ID_FILENAME), 'r') as client_file: | |
for row in client_file: | |
row = row.strip('\n').split('.') | |
client_name_id[row[1].strip(' ')] = row[0].strip(' ') | |
return client_name_id | |
def merge_files(): | |
merged_data = [] | |
client_name_id = get_client_mapping() | |
for name, id in client_name_id.items(): | |
client_file_name = name + '.csv' | |
complete_file_name = path.join(RESOURCE_DIRECTORY, client_file_name) | |
if path.isfile(complete_file_name): | |
with open(complete_file_name, 'r') as data_file: | |
next(data_file) | |
for row in data_file: | |
row = row.strip('\n').split(',') | |
merged_data.append([id, row[0].strip(' '), row[1].strip(' ')]) | |
df = pandas.DataFrame(merged_data, columns=["client_id", "timestamp", "status"]) | |
df.to_csv(path.join(RESOURCE_DIRECTORY, "merged_data.csv"), index=False) | |
merge_files() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment