前提条件
python3.8.0でプログラムを書いています.
データの整形をしたいです.
したいこと
それぞれのCSVには,
api-node.csv
api
1API_id,name,API_Category,date 21, Google Maps, Mapping, 12.05.2005 32, Twitter, Social, 12.08.2006 43, YouTube, Video, 02.08.2006 54, Flickr, Photos, 09.04.2005 65, Facebook, Social, 08.16.2006 76, Amazon Product Advertising, eCommerce, 12.02.2005 87, Twilio, Telephony, 01.09.2009 98, Last.fm, Music, 10.30.2005 109, Twilio SMS, Messaging, 02.19.2010
mashup-node.csv
mashup
1mashup_id,name, mashup_category,date 21, Product Videos For Woocommerce, Video, 07.26.2019 32, SEO Auto-Tagger, eCommerce, 07.24.2019 43, Honeygain, Monetization, 05.13.2019 54, Antideo, Spam, 04.24.2019 65, Petdoption, Animals, 04.04.2019 76, LandedCost.io Consolidated Screening List, eCommerce, 04.01.2019 87, Voice Apps, Voice, 03.31.2019 98, Best Gaming PC Deals, Coupons, 03.15.2019 109, Keyword Research Tool, Content, 03.12.2019
edge.csv
start,end,date Product Videos For Woocommerce, YouTube, 07.26.2016 Product Videos For Woocommerce, Facebook, 07.26.2017 Product Videos For Woocommerce, Vimeo, 07.26.2018 Product Videos For Woocommerce, Dailymotion, 07.26.2019 SEO Auto-Tagger, Shopify Embedded App JavaScript, 07.24.2019 Honeygain, Google AdWords, 05.13.2019 Antideo, Antideo, 04.24.2019 Petdoption, Petfinder, 04.04.2019 LandedCost.io Consolidated Screening List, Restricted Party Screening, 04.01.2019
となっています.
このedge.csvにある,startの内容をmashup-api.csvのmasup_id, endの内容をapi-node.csvのapi_idに対応させた番号にしたいと考えています.
#該当のソースコード
nametoid.py
1# -*- coding: utf-8 -*- 2 3import csv 4file1 = './data/api-node.csv' 5file2 = './data/related_api/edge2.csv' 6file3 = './data/mashup-node.csv' 7file4 = './data/node-edge.csv' 8 9with open(file1,'r',encoding='utf-8') as f: 10 with open(file2,'r',encoding='utf-8') as g: 11 with open(file3,'r',encoding='utf-8') as h: 12 i = open(file4,'w',encoding='utf-8') 13 rows1 = csv.reader(f) 14 rows2 = csv.reader(g) 15 rows3 = csv.reader(h) 16 csv_writer = csv.writer(i) 17 18 header1 = next(rows1) 19 header2 = next(rows2) 20 header3 = next(rows3) 21 22 for row2 in rows2: 23 for row1 in rows1: 24 if (row1[1]==row2[0]): 25 row3 = row1[0] 26 27 for row3 in rows3: 28 if (row3[1]==row2[1]): 29 row3 = row2[0] 30 31 csv_writer.writerow(row3) 32 33 i.close()
発生しているエラー
terminal
1python nametoid.py (git)-[master] 2Traceback (most recent call last): 3 File "nametoid.py", line 23, in <module> 4 for row1 in rows1: 5 File "/Users/tatsuma/.pyenv/versions/3.8.0/lib/python3.8/codecs.py", line 322, in decode 6 (result, consumed) = self._buffer_decode(data, self.errors, final) 7UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 2321-2322: invalid continuation byte
試したこと
すべて,文字コードをUTF-8にしましたが,だめでした.
補助情報
- macos 10.15 Catalina
です.
_
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/12/13 08:25 編集
2019/12/13 08:26
2019/12/14 18:49