xiaoairen322的个人博客分享 http://blog.sciencenet.cn/u/xiaoairen322

博文

python 获取文本中的指定行 并写入csv

已有 2640 次阅读 2021-1-20 11:56 |个人分类:python 语言学习|系统分类:科研笔记

import  os

import  linecache

import pandas  as pd 



lne=[]

fne=[]

for   root ,dirs,files in  os.walk(os.getcwd()):

    for file in files:

        filename=os.path.join(root,file)

        

        

        if filename.endswith("summary"):

            fne.append(file)

            line=linecache.getline(filename,24)

            lne.append(line)

            

count=pd.DataFrame({"count rms value ":lne,"filename":fne})

count.to_csv("count.txt",index=None,encoding="utf-8")


image.png



https://wap.sciencenet.cn/blog-3387053-1268077.html

上一篇:python pillow库 python界的ps 实现数据批量盖章 并打包成exe
下一篇:jupyter notebook 遇到的问题 " DLL load failed"
收藏 IP: 110.152.206.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-3-29 06:00

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部