Many TensorFlow examples are using TensorFlow Datasets. So the question is, how the heck you can convert your Pandas Data Frame to TensorFlow Datasets? In the example below, we create a dummy Pandas Data Frame and we convert it to a TensorFlow Dataset.
import tensorflow as tf import pandas as pd df = pd.DataFrame({'Col1':[1,2,3,4,5], 'Col2': ['a','b','c','d','e']}) df
Let’s convert it to a TensorFlow Dataset.
tf_df = tf.data.Dataset.from_tensor_slices(dict(df)) tf_df
Let’s print the first 5 rows.
for k in tf_df.take(5): print(k)