I'm still new to Python, Machine Learning and TensorFlow, but doing my best to jump right in head-first. I could use some help though.
My data is currently in a Pandas dataframe. How can I convert this to TensorFlow object? I've tried
dataVar_tensor = tf.constant(dataVar) depth_tensor = tf.constant(depth)
But, I get errors [15780 rows x 9 columns] - got shape [15780, 9], but wanted []
.
I'm sure this is probably a straightforward question, but I could really use the help.
Many thanks
ps. I'm running tensorflow 0.12 with Anaconda Python 3.5 on Windows 10
TensorFlow tensors require that all elements have the same dtype . So, in this case, you need to start treating it as a dictionary of columns, where each column has a uniform dtype . A DataFrame is a lot like a dictionary of arrays, so typically all you need to do is cast the DataFrame to a Python dict.
There's a better way. It's called PyArrow — an amazing Python binding for the Apache Arrow project. It introduces faster data read/write times and doesn't otherwise interfere with your data analysis pipeline. It's the best of both worlds, as you can still use Pandas for further calculations.
Here is one solution I found that works on Google Colab:
import pandas as pd import tensorflow as tf #Read the file to a pandas object data=pd.read_csv('filedir') #convert the pandas object to a tensor data=tf.convert_to_tensor(data) type(data)
This will print something like:
tensorflow.python.framework.ops.Tensor
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With