python 循环遍历文件夹下的同类文件(我的是csv) 并保存到数组中

# -*- coding: utf-8 -*-
import numpy as np
import pandas as pd
import os
for i in range(1,4393):#文件个数

    df = pd.read_csv('C://Users/summer/Desktop/23/new idea/out-in/output/'+ str(i) +'.csv')  # 返回一个DataFrame的对象,这个是pandas的一个数据结构
    df.columns = ["Col1", "Col2", "Col3", "Col4", "Col5", "Col6", "Col7", "Col8"]

    X = df[["Col1", "Col2", "Col3", "Col4", "Col5", "Col6", "Col7", "Col8"]]  # 抽取前七列作为训练数据的各属性值
    X = np.array(X) # 存到数组中
    print(X)

 

你可能感兴趣的:(python,文件读取)