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

Here I am getting a csv file and reading the "TV" values ​​by calculating the average and printing with the tensor method. But I am getting that there is no size attribute in the "AttributError" list. Can anyone 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)

      

+3


source to share


1 answer


As a summary of the discussion in the comments, here are valid ways to get the length of a 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 a tensorflow session):

$ import numpy as np
$ print np.mean(series)
1.2

      

+2


source







All Articles