pandas遍历文件夹提取单个文件中的部分列集合

import pandas as pd
import numpy as np
import os

InputDir = r'D:\workfile\juanworkfile\R\P'

rootdir = InputDir

sududfInitialWithHeight=pd.read_csv(r'D:\workfile\juanworkfile\R\P\Z_RADA_I_57793_20130628000000_P_WPRD_LC_ROBS.TXT',skiprows=3,header=None,nrows=99,sep=' ').iloc[:,0]
for parent,dirnames,filenames in os.walk(rootdir):

     for filename in filenames:

        df=pd.read_csv(os.path.join(parent,filename),skiprows=3,header=None,nrows=99,sep=' ')
        localdf = sududfInitialWithHeight
        pieces=[localdf,df.iloc[:,2]]
        sududfInitialWithHeight=pd.concat(pieces,axis=1)

sududfInitialWithHeight.to_csv('sudu.txt')   这里写代码片
    原文作者:wangquannuaa
    原文地址: https://blog.csdn.net/wangquannuaa/article/details/44259289
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞