读取.csv数据/写入另外一个.csv (Python)
2016-07-21 21:13
507 查看
def test(src, dst, index): with open(dst, 'wb') as df: with open(src, 'rb') as csvfile: # 使用reader函数,接收一个可迭代的对象 reader = csv.reader(csvfile) # 列表解析 rows = [row for row in reader] # 根据索引提取其中某一列 column = [row[index]for row in reader] # 初始化一个二维矩阵 b = numpy.array(rows) # (125973, 41) # 将list中的字符转为数字 column_f = map(float, column) # 给每个列表中的每个元素进行归一化 # for i in column_f: # newValue = (i - min(column_f)) / (max(column_f) - min(column_f)) # print(newValue) writer = csv.writer(df) # 执行写操作 writer.writerows(column) # 关闭文件 df.close() if __name__ == "__main__": test('ss.csv', 'test.csv', 0)
相关文章推荐
- python 学习 笔记1
- Python time和logging模块
- 分析python处理基本数据<四>
- python开源IP代理池--IPProxys
- The Python Tutorial - Input and Output
- python--模块
- python-django
- python核心编程学习笔记-2016-07-21-01-decimal模块
- 将sublime打造成python的IDE开发工具
- python 数据初学者 小记
- Python学习-反射相关函数
- windows7下Python环境搭建
- 转载:深入解读Python解析XML的几种方式
- Python 练习册,每天一个小程序(0000)
- Learning Python 011 高级特性 2
- Learning Python 011 高级特性 2
- Python篇----Requests获取网页源码(爬虫基础)
- 新手疑惑:谈谈python 中__name__ = '__main__' 的作用
- 不可不知的Python模块: collections
- "Python"学习笔记----简单文件处理