我的数据集应为大括号集/字典时显示字符串 - python

我的数据集有一列,在打印数据框时,该列中的每个条目都像这样:
{"Wireless Internet","Air conditioning",Kitchen}

我想更正此错误

在控制台中打印此内容后,python将打印此内容:'{"Wireless Internet","Air conditioning",Kitchen}'请注意大括号中的引号,因为python正在打印字符串。
理想情况下,我想找到一种方法将其转换为类似["Wireless Internet","Air conditioning","Kitchen"]的列表,但我不知道如何。此外,请注意有些单词怎么没有引号,例如Kitchen。我不知道如何解决这个问题。

谢谢

参考方案

如果是字符串,请从字符串中删除双引号和大括号,然后使用逗号分隔,您将获得所需的结果

'{"Wireless Internet","Air conditioning",Kitchen}'.replace('{','').replace('}','').replace('"','').split(',')

#op
['Wireless Internet', 'Air conditioning', 'Kitchen']

python JSON对象必须是str,bytes或bytearray,而不是'dict - python

在Python 3中,要加载以前保存的json,如下所示:json.dumps(dictionary)输出是这样的{"('Hello',)": 6, "('Hi',)": 5}当我使用json.loads({"('Hello',)": 6,…

Python:使用两个列表进行字典 - python

如何使用python使用两个列表作为字典list_one_keys = ['key1', 'key2', 'key3', 'key4'] 嵌套列表:list_two_values = [['a1var1', 'a1var2', '…

在返回'Response'(Python)中传递多个参数 - python

我在Angular工作,正在使用Http请求和响应。是否可以在“响应”中发送多个参数。角度文件:this.http.get("api/agent/applicationaware").subscribe((data:any)... python文件:def get(request): ... return Response(seriali…

Python uuid4,如何限制唯一字符的长度 - python

在Python中,我正在使用uuid4()方法创建唯一的字符集。但是我找不到将其限制为10或8个字符的方法。有什么办法吗?uuid4()ffc69c1b-9d87-4c19-8dac-c09ca857e3fc谢谢。 参考方案 尝试:x = uuid4() str(x)[:8] 输出:"ffc69c1b" Is there a way to…

Python exchangelib在子文件夹中读取邮件 - python

我想从Outlook邮箱的子文件夹中读取邮件。Inbox ├──myfolder 我可以使用account.inbox.all()阅读收件箱,但我想阅读myfolder中的邮件我尝试了此页面folder部分中的内容,但无法正确完成https://pypi.python.org/pypi/exchangelib/ 参考方案 您需要首先掌握Folder的myfo…