Home>
Dp matching is created by referring to the following contents.
I want to use two csv files for comparison, is there only one? Doesn't it work because it's a number rather than a string? .. I'm sorry I don't understand. I would appreciate it if you could teach me. I look forward to working with you.
import difflib
import Levenshtein
from pprint import pprint
text_filepath ='../Desktop/m122.csv'
results = []
# File reading/similarity calculation processing
with open (../Desktop/m1.csv,'r') as fr:
# # Header creation
header = fr.readline ()
header = header.strip ()
columns = header.split ('\ t')
columns.extend (['Gestalt_1','Gestalt_2','Levenshtein','Jaro_Winkler'])
results.append (columns)
for line in fr.readlines ():
line = line.strip ()
data = line.split ('\ t')
str1 = data [0]
str2 = data [1]
# 1. Gestalt pattern matching
gestalt1 = difflib.SequenceMatcher (None, str1, str2) .ratio ()
gestalt2 = difflib.SequenceMatcher (None, str2, str1) .ratio ()
data.append (gestalt1)
data.append (gestalt2)
# 2. Levenshtein distance
lev_dist = Levenshtein.distance (str1, str2)
## Standardization
divider = len (str1) if len (str1)>len (str2) else len (str2)
lev_dist = lev_dist/divider
lev_dist = 1 --lev_dist
data.append (lev_dist)
# 3. Jaro Winkler Distance
jaro_dist = Levenshtein.jaro_winkler (str1, str2)
data.append (jaro_dist)
# Rounded to 4 decimal places for display
data [2:] = [round (x, 4) for x in data [2:]]
results.append (data)
# Export results
result_filepath ='../Desktop/mmm.txt'
with open (result_filepath,'w') as fw:
for result in results:
print ('\ t'. join (map (str, result)), file = fw)
File "<ipython-input-11-06fb6b37c5de>", line 10
with open (/Desktop/m1.csv,'r') as fr:
^ ^
SyntaxError: invalid syntax
-
Answer # 1
Related articles
- i have a question about basic python problems
- python - what i don't understand about yolo9000 (v2)
- python - about write loop to csv
- about python argument and data definition
- python 3x - about downloading anaconda
- python - about the optimum angle of rotation matrix
- python - about downloading youtube videos by youtube-dl
- about processing to exclude the character string group specified from list in python
- about batch change of file name using python
- python, about the fire spread step of forest fire simulation
- about the python speedtest code
- about the implementation of combinations in python
- please tell me about the role of python tag = "mychr"
- about python def issues
- about the operation of python's speedtest module (library)
- pythonista - [python] questions about line splitting in dataframe
- python - about hamiltonian neural networks
- python - about "" "of" "" select === = "" "
- python - about kaggle's titanic: fare's histogram doesn't appear
- python - i'm not sure about add_axes in matplotlib
Trends
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- python - you may need to restart the kernel to use updated packages error
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- python 3x - typeerror: 'method' object is not subscriptable
- javascript - how to check if an element exists in puppeteer
- xcode - pod install [!] no `podfile 'found in the project directory
- i want to call a child component method from a parent in vuejs
- vuejs - [vuetify] unable to locate target [data-app] i want to unit test to avoid warning
Looks like an error where the file path is not quoted