当前第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中的super()和__init__()方法有什么用
如何使用vscode愉快的写Python于调试配置步骤_Python
Python中关于装饰器级连的示例
Python中func什么意思
Python是脚本语言吗
Python如何计算1到100的和
Python中如何在一个函数中加入多个装饰器
Python使用cx_oracle模块操作oracle数据库详解
Python 限制函数调用次数
eval在Python什么意思
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » python怎么批量读取txt文件为DataFrame格式