Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError:'list' object has no attribute 'size'

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)
like image 565
Raghavi Avatar asked Jul 14 '17 08:07

Raghavi


1 Answers

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
like image 104
Maxim Avatar answered Sep 28 '22 05:09

Maxim