当前第2页 返回上一页
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | import os
import pandas
import codecs
import glob
import pandas as pd
os. getcwd ()
os. chdir ( 'D:\AAAASXQ\python study\data preprocessing' )
def txtcombine():
files = glob . glob ( '*.txt' )
all = codecs.open( 'all.txt' , 'a' )
for filename in flist:
print (filename)
fopen =codecs.open(filename, 'r' ,encoding= 'utf-8' )
lines=[]
lines= fopen .readlines()
fopen .close()
i=0
for line in lines:
for x in line:
all.write(x)
#读取为DataFrame格式
all1 = pd.read_csv( 'all.txt' ,sep= ' ' ,encoding= 'GB2312' )
#保存为csv格式
all1.to_csv( 'all.csv' ,encoding= 'GB2312' )
if name == 'main' :
txtcombine()
|
相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!
推荐阅读:
python字符串如何转为二维数组
JS的EventEmitter使用步奏详解
以上就是python怎么批量读取txt文件为DataFrame格式的详细内容,更多文章请关注木庄网络博客!!
返回前面的内容
相关阅读 >>
Python安装扩展包教程
Python如何运行一个Python程序
Python能做什么?Python爬虫是什么?
Python为什么要装32位的
Python矩阵中常见运算的示例代码分享
关于Python函数的深度解剖
Python实现网页中下载的功能实例
Python实现购物系统实例介绍
Python中none表示什么
Python继承是什么
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » python怎么批量读取txt文件为DataFrame格式