我在这里的目标是使用字典为每个单独的列清理CSV文件中的地址数据。有点像自动化excel的查找和替换功能。地址分为列。^{{cd2> 当代码正常工作时,我需要有单独的字典,因为有些列需要特定的输入错误修复。用于例如, 我不知道该怎么做,我觉得这很简单,或者我需要熊猫,但我不确定如何继续。谢谢你的帮助!还有没有什么方法可以把拼写错误和一个正确的错误组合在一起?我尝试了下面的方法,但是得到了一个不可修复的类型错误。在missad = {
'Typo goes here': 'Corrected typo goes here'}
def replace_all(text, dic):
for i, j in missad.items():
text = text.replace(i, j)
return text
with open('original.csv','r') as csvfile:
text=csvfile.read()
text=replace_all(text,missad)
with open('cleanfile.csv','w') as cleancsv:
cleancsv.write(text)
Housenumbers
列housenum
,stdir
表示街道方向等,每个列都有其特定于列的类型:missad = {
['Typo goes here',Typo 2 goes here',Typo 3 goes here']: 'Corrected typo goes here'}
你在找这样的东西吗?在
把这个想法用在其他感兴趣的专栏上。在
相关问题 更多 >
编程相关推荐