Python str list to list
eg1:
My csv data like this below,i wt count list nums
2018上,"['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[]
ya = d[] # '[\\'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 str.format 方法被用于字符串的格式化输出。
#python str.format 方法被用于字符串的格式化输出. #''.format() print('{0}+{1}={2}'.format(1,2,3)) #1+2=3 可见字符串中大括号内 ...
- Python str() 函数
Python str() 函数 Python 内置函数 描述 str() 函数将对象转化为适于人阅读的形式. 语法 以下是 str() 方法的语法: class str(object='') 参数 ...
- Python str 与 bytes 类型(Python2/3 对 str 的处理)
本文均在 Python 3 下测试通过,python 2.x 会略有不同. 1. str/bytes >> s = '123' >> type(s) str >> ...
- Python str & repr
Python str & repr repr 更多是用来配合 eval 的 (<- 点击查看),str 更多是用来转换成字符串格式的 str() & repr() str() 和 ...
- Python str方法总结
1.返回第一个字母大写 S.capitalize(...) S.capitalize() -> string 1 2 3 4 >>>a = 'shaw' >>> ...
- python str()与repr()
相同点: 将任意值转为字符串 不同点: str()致力于生成一个对象的可读性好的字符串表示,它的返回结果通常无法用于eval()求值,但很适合用于print语句输出 repr()出来的值是给pytho ...
- Python str字符串常用到的函数
# -*- coding: utf-8 -*- x='pythonnnnnnoooo' print type(x) # <type 'str'> 输出类型 print x.capitali ...
- python str.format()
python中的字符串格式函数str.format(): #使用str.format()函数 #使用'{}'占位符 print('I\'m {},{}'.format('Hongten','Welco ...
- python str的一些方法
在python有各种各样的string操作函数.在历史上string类在python中经历了一段轮回的历史.在最开始的时候,python有一个专门的string的module,要使用string的方法 ...
- python - str和repr方法:
# python 内置__str__()和__repr__()方法: #显示自定制 # 示例1 # a = 123 # print(a.__str__()) # 示例2 class Test(): d ...
随机推荐
- C# ORM修改实体层
实体层:[数据库中是么以偶Contents2这个字段的],之所以在实体层添加一个Contents2,是因为: 所以在添加之后: 返回json形式,就用Contents,后台添加就用Contents2. ...
- (转)开放window是服务器端口——以8080为例
本文记录两个内容: 1.win7下打开端口 2.服务器(2003或者其他老版的系统以2003为例) 测试端口时 可用telnet 命令 侦听端口:C:\Documents and Settings\a ...
- [Unity插件]Lua行为树(八):行为节点扩展
先看一下之前的行为节点是怎么设计的: BTAction.lua BTAction = BTTask:New(); local this = BTAction; this.taskType = BTTa ...
- python2.7 urllib2 爬虫
# _*_ coding:utf-8 _*_ import urllib2import cookielibimport randomimport refrom bs4 import Beautiful ...
- python中from __future__ import division
ppython2.7版本中整数相除得出的结果不显示小数 a = 9 / 2 print(a) 输出结果: 4 此时就需要调用from __future__ import division 1 from ...
- Flex Iris效果放大或缩小组件演示
Iris效果通过扩展或收缩集中在目标上的矩形遮罩为效果目标设置动画.该效果可以从目标的中心放大遮罩来显示目标,也可以向中心收缩遮罩来隐藏目标.演示: 源码如下: <?xml version=&q ...
- pl/sql学习笔记---马士兵教程38-48
Procedure Language/Structure query Language 一.关于语言学习 1.数据类型 2.语法 通过例子来学习很快就能明白 set serverputout on ...
- eclipse插件spket安装
1.
- python 网页爬虫,带登陆信息
注意点: 1. 用Fiddler抓取登陆后的headers,cookies; 2. 每抓取一次网页暂停一点时间防止反爬虫; 3. 抓取前,需要关闭Fiddler以防止端口占用. 还需解决的问题: 爬取 ...
- day27-反射
1.介绍 反射的概念是由Smith在1982年首次提出的,主要是指程序可以访问.检测和修改它本身状态或行为的一种能力(自省).这一概念的提出很快引发了计算机科学领域关于应用反射性的研究.它首先被程序语 ...