【问题标题】:exclude files from a list with certain length从具有特定长度的列表中排除文件
【发布时间】:2020-04-07 03:37:02
【问题描述】:

我正在尝试在排除一定长度后打印文件名列表。以下是我目前所拥有的。

import glob
import numpy as np
import pandas as pd

path=r'Directory'
files=glob.glob(path + '/**/*.cod',recursive=True)

for i in files:
    indat = pd.read_csv(i, skiprows=4, header=None, engine='python')
    a=indat[8]
    if len(a) >= 600:
       print() #want a list of file names that the files that have length >=600.

【问题讨论】:

  • 你试过print(i)吗?
  • @KaanE。谢谢!它工作。
  • no pb 也欢迎接受我的回答。

标签: python-3.x pandas for-loop if-statement


【解决方案1】:

当您来到len(a) > 600 时,您已经过滤掉了少于 600 个的文件,因此您只需将代码更改为以下内容:

for i in files:
    indat = pd.read_csv(i, skiprows=4, header=None, engine='python')
    a=indat[8]
    if len(a) >= 600:
       print(i)

【讨论】:

    猜你喜欢
    • 2017-10-10
    • 2022-10-04
    • 1970-01-01
    • 1970-01-01
    • 2020-12-19
    • 1970-01-01
    • 1970-01-01
    • 2020-09-25
    • 1970-01-01
    相关资源
    最近更新 更多