Python yaml解析错误

时间:2018-05-08 05:51:53

标签: python-3.x yaml

import pandas as pd
import yaml as y

Movies = pd.read_csv('tmdb_5000_movies.csv',encoding="ISO-8859-1")
company = pd.DataFrame(Movies[['original_title','production_companies']])
for idn in range(10000):
    for index in range(len(company['original_title'])):
        akm = y.load(company.loc[index,'production_companies'])
        for i in range(len(akm)):
            if akm[i]['id'] == idn:
                if str(idn) not in keyword.columns:
                    keyword[str(idn)] = " "    
                    keyword.loc[index,str(idn)] = 1
                elif str(idn) in keyword.columns:
                    keyword.loc[index,str(idn)] = 1
            # check if akm == idn
        # akm length
        keyword = keyword.fillna(0)

我的数据:

[{"id": 416, "name": "miami"},
 {"id": 529, "name": "ku klux klan"},
 {"id": 701, "name": "cuba"},
 {"id": 1568, "name": "undercover"},
 {"id": 1666, "name": "mexican standoff"},
 {"id": 1941, "name": "ecstasy"},
 {"id": 7963, "name": "guant\u00e1namo"},
 {"id": 10089, "name": "slaughter"},
 {"id": 10950, "name": "shootout"},
 {"id": 12371, "name": "gunfight"},
 {"id": 12648, "name": "bromance"},
 {"id": 13142, "name": "gangster"},
 {"id": 14819, "name": "violence"},
 {"id": 14967, "name": "foot chase"},
 {"id": 15271, "name": "interrogation"},
 {"id": 15483, "name": "car chase"},
 {"id": 18026, "name": "drug lord"},
 {"id": 18067, "name": "exploding house"},
 {"id": 155799, "name": "narcotics cop"},
 {"id": 156117, "name": "illegal drugs"},
 {"id": 156805, "name": "dea agent"},
 {"id": 167316, "name": "buddy cop"},
 {"id": 179093, "name": "criminal underworld"},
 {"id": 219404, "name": "action hero"},
 {"id": 226380, "name": "haitian gang"},
 {"id": 226381, "name": "minefield"}]

错误消息(从以下评论中复制):

ParserError: while parsing a flow mapping in "<unicode string>", line 1, column 2: {""name"": ""Dune Entertainment"" ^ expected ',' or '}', but got '<scalar>' in "<unicode string>", line 1, column 5: {""name"": ""Dune Entertainment"" ^

0 个答案:

没有答案