-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDB Filter Script
39 lines (31 loc) · 1.24 KB
/
DB Filter Script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# -*- coding: utf-8 -*-
"""
Created on Sat May 30 14:14:14 2020
@author: MRGiacalone
"""
import pandas as pd
# DB Filter Script
# ============================================================================================================
# Script for filtering a DB: Remove strings atarting with Filt, keep first column only, and strip column names
# ============================================================================================================
# Define filters to leave out of DB. Example: filt = ("Not", "Another", "Filter")
stringFilter = ([], [], [], etc...)
# Define input path and file name. Example: file = 'X:/XYZ/123/FILENAME'
fileInput = []
# Define output path and file name. Example: file = 'X:/XYZ/123/NEWFILENAME'
fileOtput = []
# Default separator ";".
print('Reading DB.....')
base = pd.read_csv(fileInput, sep=';')
print('Reading Done!')
print('Modifying DB.....')
base = base.iloc[:, [0]]
base.columns=['Col1']
base = base[~base.Col1.str.startswith(stringFilter)]
base.reset_index(drop=True, inplace=True)
base.drop(base.tail(1).index,inplace=True)
print('Modifying Done!')
# Write the first column to the output file
print('Writing DB.....')
base.to_csv(fileOutput, mode='a', header=False, index = None)
print('All Done!')