Created
October 5, 2018 14:32
-
-
Save jgarciabu/9692d45a13fb68ba81c9f18e9f7dcc35 to your computer and use it in GitHub Desktop.
Remove rows from file that cause failure in processing
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
# -*- coding: utf-8 -*- | |
""" | |
Created on Wed Jul 18 09:05:18 2018 | |
@author: jeffrey.garcia | |
""" | |
import pandas as pd | |
import os | |
import inspect; os.path | |
from os import listdir | |
filename = inspect.getframeinfo(inspect.currentframe()).filename | |
path = os.path.dirname(os.path.abspath(filename)) | |
firstfilenamelist = listdir(path) | |
v = input("Input what you need to find as a pipe delimited list: ") | |
w = v.split('|') | |
yourfilename = input("Please input the file you'd like edit: ") | |
encase = input("Please input the character your values is surrounded by: ") | |
valueslist = [] | |
for item in w: | |
valueslist.append(encase + item + encase) | |
with open(yourfilename,"r") as readinput: | |
base = os.path.basename(path + '\\' + yourfilename) | |
noextfilename = os.path.splitext(base)[0] | |
new_filename = noextfilename + '_A' | |
with open(new_filename, "w") as writeoutput: | |
for line in readinput: | |
if any(x in line for x in valueslist): | |
continue | |
else: | |
writeoutput.write(line) | |
input('Press Enter to Close') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment