-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import pandas as pd | ||
import csv | ||
import argparse | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument('-i', '--fin', help='path to the input file') | ||
parser.add_argument('-o', '--fout', help="path to the output file, use input file path if not provided", nargs='?') | ||
parser.add_argument('-q', '--quoting', help='quoting style of the output [all, minimal, ...] (not case sensitive) ' | ||
'see list in https://docs.python.org/3/library/csv.html#csv.QUOTE_ALL', default='all') | ||
|
||
def to_quote(*, fin, fout=None, quoting=csv.QUOTE_ALL): | ||
if fout is None: | ||
fout = fin | ||
df = pd.read_csv(fin, dtype=str, keep_default_na=False, na_values=[], encoding='latin_1') | ||
df.to_csv(fout, index=False, quoting=quoting) | ||
|
||
def main(): | ||
kwargs = vars(parser.parse_args()) | ||
quoting = getattr(csv, f"QUOTE_{kwargs.pop('quoting').upper()}") | ||
|
||
to_quote(quoting=quoting, **kwargs) | ||
|
||
if __name__ == '__main__': | ||
main() | ||
|
||
|
||
|
||
|
||
|
||
|
||
|