Here I am jus extracting a csv file and reading the "TV"values, calculating average and printing using tensorflow. But I am getting "AttributError" list has no attribute 'size' ". Can anyone please help me? Thanks in advance.
import tensorflow as tf
import pandas
csv = pandas.read_csv("Advertising.csv")["TV"]
t = tf.constant(list(csv))
r = tf.reduce_mean(t)
sess = tf.Session()
s = list(csv).size
fill = tf.fill([s],r)
f = sess.run(fill)
print(f)
As summary of the discussion in the comments, here are valid ways of getting a length of the column in csv
:
$ csv = pandas.read_csv("Advertising.csv")
$ print type(csv), len(csv)
<class 'pandas.core.frame.DataFrame'> 10
$ series = csv["TV"]
$ print type(series), len(series)
<class 'pandas.core.series.Series'> 10
$ as_list = list(series)
$ print type(as_list), len(as_list)
<type 'list'> 10
And here's how to calculate the average (without tensorflow session):
$ import numpy as np
$ print np.mean(series)
1.2
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