【发布时间】:2018-04-29 15:56:34
【问题描述】:
我有一个文件夹,里面有 30 个 CSV 文件,名称各不相同。
我想遍历所有文件并分别使用 pandas 读取它们,并将它们存储在列表列表中。在单独阅读它们时,我还想同时从中删除一些变量,例如删除相关的列。
目前,我正在尝试这样做。
import glob
import pandas as pd
path = os.getcwd()
# Get folder path containing text files
file_list = glob.glob(path + '/*.csv')
data = []
for file_path in file_list:
data.append(
pd.read_csv(file_path).drop(['column1', 'column2'], axis =1))
# now you can access it outside the "for loop..."
for d in data:
print(d)
所以,我想将每个数据帧作为二维列表存储在一个列表中并训练我的模型,因为每个 [ [CSV][2] ][3] 文件都是一个观察值。我的 CSV 文件有 (5000,12) 个观察值。每个 CSV 或实例都有标签,即文件名。
不知道我是否朝着正确的方向前进。
len(data)
# 30
label = [1,1,1,1,1,1,1,1,1,1,,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3]
max_length = 25 # shape of data frame after removing two variables
# define the model
model = Sequential()
model.add(Dense(24, input_dim=25, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
# compile the model
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['acc'])
# summarize the model
print(model.summary())
【问题讨论】:
标签: python python-3.x pandas neural-network