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 ...
随机推荐
- official shiro(Reference Manual)
Apache Shiro Reference Documentation Overview Core Spring-based Applications 1.Overview pom.xml < ...
- 推荐算法 pd
from django.db import connection select_sql = 'select * from model' datas = pd.read_sql(select_sql, ...
- tpc资料汇总
官方资料 TPC官网 http://www.tpc.org/ 配置文档 大家一起来测试,benchmark起来(MySQL下的TPC-C,TPC-H,TPC-W) http://www.itpub ...
- 网站分析基础及KPI实践
一:网站分析是什么? 网站分析(Web Analytics)即网站访客行为分析,通过对网站数据进行定量和定性的分析,来不断驱动和提高访问者在网站中的体验,并将访客转化为你的商业目标(在线及离线KPI) ...
- 初窥GPFS文件系统(转)
原文地址:http://blog.csdn.net/jznsmail/article/details/5502840?reload 本作品采用知识共享署名-非商业性使用-相同方式共享 3.0 未本地化 ...
- Call to undefined function think\finfo_open() 报错 解决方法
Call to undefined function think\finfo_open() 经过各方面排查,是fileinfo扩展没有安装 安装即可
- Getting started with C# and GDAL
Getting started with C# and GDAL http://vipassanaandenvironmentalinformatics.blogspot.jp/2013/03/get ...
- WPF线性渐变画刷应用之——炫彩线条
效果图: Xaml代码: <Rectangle Width="800" Height="10"> <Rectangle.Fill> &l ...
- 【版本发布】JAVA微服务开发框架,Jeecg-P3 1.0.0 重构版本发布
1.项目介绍 Jeecg-P3是一个微服务框架,采用插件式模式开发:业务插件以JAR方式提供,松耦合可插拔支持独立部署,也可无缝集成Jeecg平台中,目前jeecg已经提供了在线聊天,我的邮箱等一系列 ...
- js ajax 数据获取
在js中应用ajax 获取数据的方法,也写一个出来供复习所用 1.建议一个user.json 文件如下,保存名字为 user.json { "name": "huanyi ...