Python str list to list,,eg1:My csv
Python str list to list,,eg1:My csv
eg1:
My csv data like this below,i wt count list nums2018上,"[‘C‘, ‘B‘, ‘B‘, ‘B‘, ‘D‘, ‘A‘, ‘B‘, ‘C‘, ‘A‘, ‘D‘, ‘B‘, ‘D‘, ‘A‘, ‘A‘, ‘A‘, ‘C‘, ‘D‘, ‘B‘, ‘C‘, ‘B‘, ‘A‘, ‘C‘, ‘A‘, ‘D‘, ‘A‘, ‘D‘, ‘B‘, ‘D‘, ‘B‘, ‘C‘, ‘B‘, ‘A‘, ‘D‘, ‘B‘, ‘C‘, ‘B、C‘, ‘B‘, ‘B‘, ‘B‘, ‘D‘, ‘B‘, ‘C‘, ‘C‘, ‘B‘, ‘B‘, ‘D‘, ‘A‘, ‘D‘, ‘D‘, ‘C‘, ‘B‘, ‘B‘, ‘A‘, ‘B‘, ‘C‘, ‘B‘, ‘B‘, ‘B‘, ‘A‘, ‘A‘, ‘A‘, ‘C‘, ‘A‘, ‘B‘, ‘A‘, ‘A、A‘, ‘B、C‘, ‘C‘, ‘D‘, ‘B‘, ‘C‘, ‘C‘, ‘A‘]"eg:df_data = np.array(pd.read_csv(answer_file, header=None)) new_data = [] for d in df_data: y = d[0] ya = d[1] # ‘[\\‘C\\‘,\\‘A\\‘]‘
#(1)check one y2 = np.array(ya) # [‘C‘,‘A‘] #this is what i not want
y2_test = y2.shape # 0-d
y2_test2 = y2.tolist() # dtype shows not list
#the right methon
#(2)check one
ls = ya.strip(‘][‘).split(‘,‘) # dtype show list
#(3) right methon
import ast
ls = ast.iteral_eval(ya)
ls = [i.strip() for i in ls]
Python str list to list
相关内容
- python+mysql+flask创建一个微博应用(持续更新),,微博应
- python为什么会有@classmethod?,,今天被问了这么个问题
- Python之在字符串中处理html和xml,,需求:替换文本字符
- python字典键值对新增与修改的几种方法及差异总结,
- python 使用 elasticsearch 常用方法(聚合),,#记录聚合查
- Python处理PDF和Word文档常用的方法,, Python
- Python 函数名作为字典值,, Python中是
- python实现冒泡排序,,代码#!/usr/b
- python 运行sum函数的使用,,sum(iterab
- Python爬虫--- 1.1请求库的安装与使用,,原文链接:http
评论关闭