Converting a pandas DataFrame into a TensorFlow Dataset
Often when working on a deep learning model you will retrieve your source data in a pandas.DataFrame
and need to convert it into a format that Tensorflow can read. Fortunately, Tensorflow now has Datasets which create data pipelines for your network to train on. Converting a DataFrame
into a tf.data.Dataset
is straight-forward. The code below shows how to take a DataFrame
with 3 randomly generated features and 3 target classes and convert it into a TensorFlow Dataset. The code uses eager execution mode, but the code will also work when using an execution graph. After the DataSet
is created, you can run batch
, shuffle
and other functions to pre-process the data before training.