I have an excel file with 1000 sheets and each sheet contain a dataframe. In order to feed my model with these data, I try to convert it to 1000 batches of tensors and here's my code:
df = pd.read_excel('file.xlsx', sheet_name=None)
file_names = list(df.keys())
columns = ['A','B','C']
features = []
labels = []
for n in file_names:
df = pd.read_excel('file.xlsx', sheet_name=n)
features.append(df[columns].to_numpy())
labels.append(df['D'].to_numpy())
Y = tf.convert_to_tensor(np.stack(labels), dtype=tf.float32)
X = tf.convert_to_tensor(np.stack(features), dtype=tf.float32)
dataset = tf.data.Dataset.from_tensor_slices((X, Y))
My code works fine, but it takes over an hour to iterate it. I will have more than 1000 batches of data in the future so it seems not a good idea to have several thousand of csv files. How can I speed up the process?