0

I successfully added a cutoff option to get_close_matches in Pandas. For some reason when I add cutoff=0.7, when it outputs to my CSV, it reads as ['Name']. When it did not have the cutoff argument, it just outputted the match with no ['']. Below is my code. Any help would be appreciated!

https://pastebin.com/nRt3rVPr

import sys
import difflib
import csv
import pandas as pd

df = pd.read_csv(sys.argv[1])
List = df.list #.astype(str).values.tolist()
MappedID = df.Party.astype(str)
df['Name_r'] = MappedID.map(lambda x: (difflib.get_close_matches(x, List, cutoff=0.7)[:1] or [None][0]))
header = [ "List", "Party", "Name_r"]
df.to_csv(sys.argv[2], columns = header)
print(df.to_string())
  • Please provide a [reproducible example](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples). – iDrwish Apr 20 '18 at 16:16

1 Answers1

0

Specify no quoting.

df.to_csv(sys.argv[2], columns=header, quoting=csv.QUOTE_NONE)
iDrwish
  • 3,085
  • 1
  • 15
  • 24