python中数据的保存
2016-04-01 10:34
671 查看
1.将list中的数据写入到excel文件中
利用python包numpy(实现方式应该有许多种,这里只是记录成功实现的一种)中的savetxt局限性:要保存的list可以为[1,2,3,4,5]这种形式,也可以是[[1,2,3,4,5],[6,7,8,9,10],[11,12,13,14,15]]这种形式,但如果是第二种情况(list中每个元素都为list)时,list中的每个list所含有元素个数要相同,这是因为该方法需要先将python的list数据转化为array类型
利用python包numpy(实现方式应该有许多种,这里只是记录成功实现的一种)中的savetxt局限性:要保存的list可以为[1,2,3,4,5]这种形式,也可以是[[1,2,3,4,5],[6,7,8,9,10],[11,12,13,14,15]]这种形式,但如果是第二种情况(list中每个元素都为list)时,list中的每个list所含有元素个数要相同,这是因为该方法需要先将python的list数据转化为array类型
import numpy as np # python list that is needed to be save in the csv file data_list = [1,2,3,4,5,6,7,8] print type(data_list) # convert list to array data_array = np.array(data_list) print type(data_array) # saving... np.savetxt('data.csv',data_array,delimiter=',') print 'Finish saving csv file'结果:
<type 'list'> <type 'numpy.ndarray'> Finish saving csv file
1 import numpy as np 2 # python list that is needed to be save in the csv file 3 data_list = [[1,2,3,4,5,6,7,8],[9,10,11,12,14,1,2,3],[4,3,2,1,3,6,7,8]] 4 print type(data_list) 5 # convert list to array 6 data_array = np.array(data_list) 7 print type(data_array) 8 # saving... 9 np.savetxt('data.csv',data_array,delimiter=',') 10 print 'Finish saving csv file'结果
<type 'list'> <type 'numpy.ndarray'> Finish saving csv file
相关文章推荐
- 利用Anaconda安装python后,如何安装opencv-python
- Python/Keras如何将给定的数据集打乱
- Python如何进行cross validation training
- Python常用函数
- Python如何读取指定文件夹下的所有图像
- python相关的工具
- 开始学习Python
- python pexpect
- Python脚本执行MySQL语句时停住
- [置顶] win10安装Python出现问题解决方法
- numpy.ndarray.flat/flatten 与 Spark 下的 flatMap
- Day3、Python
- python学习笔记(session)
- Python函数的各种参数(含星号参数)
- Python 基础 —— re:正则表达
- Python中遇到"UnicodeDecodeError: ‘gbk’ codec can’t decode bytes in position 2-3: illegal multibyte sequ
- python基于隐马尔可夫模型实现中文拼音输入
- Python 2.x vs Python 3.x(四)—— TypeError: unhashable type
- python3.5 + django1.9.1+mysql
- python中的条件语句,分支语句以及逻辑运算符和比较运算符