Skip to content

Instantly share code, notes, and snippets.

@hyzhak
Last active November 8, 2018 10:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hyzhak/86101fc3c4a0aa75dd8e89283c9521fb to your computer and use it in GitHub Desktop.
Save hyzhak/86101fc3c4a0aa75dd8e89283c9521fb to your computer and use it in GitHub Desktop.
Convert tensorflow dataset to pandas dataframe
import pandas as pd
import tensorflow as tf
def convert_tf_to_pd(ds, limit=32):
"""
Read data from Tensorflow dataset to Pandas dataframe
:param ds:
:param limit:
:return:
"""
batch_iterator = ds.batch(limit).make_one_shot_iterator()
with tf.Session() as sess:
batch = batch_iterator.get_next()
features_and_labels = sess.run(batch)
samples = {
**features_and_labels[0],
'label': features_and_labels[1],
}
return pd.DataFrame.from_dict(samples)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment