How to convert pandas dataframe to tensorflow dataset?

Issue

I am reading a csv file into a pandas dataframe.

train_data = pd.read_csv('mnist_test.csv');

Sample data

   label  pixel1  pixel2  pixel3  ...  pixel781  pixel782  pixel783  pixel784
0      6     149     149     150  ...       106       112       120       107
1      5     126     128     131  ...       184       184       182       180
2     10      85      88      92  ...       226       225       224       222
3      0     203     205     207  ...       230       240       253       255
4      3     188     191     193  ...        49        46        46        53

how can I convert this dataframe into a tensorflow dataset.

Solution

import tensorflow as tf
ds = tf.data.Dataset.from_tensor_slices(dict(train_data))

See tensorflow.org/tutorials/load_data/pandas_dataframe for details.

Answered By – proedig

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published