0

So, this is my dataframe:

    date_trunc  count
0   2020-06-01  34
1   2020-06-02  28
2   2020-06-03  32
3   2020-06-04  27
4   2020-06-05  29
5   2020-06-06  24
6   2020-06-07  13
7   2020-06-08  36
8   2020-06-09  43
9   2020-06-10  40

I need to make a list out of the two columns date_trunc and count. So I used this code:

result_list = []
sales_dates = list(df[-7:].date_trunc)
act_sales = list(df[-7:].count)

However, I got this error code from Python:

TypeError                                 Traceback (most recent call last)
<ipython-input-45-799435de2bb5> in <module>
      2 result_list = []
      3 sales_dates = list(df[-7:].date_trunc)
----> 4 act_sales = list(df[-7:].count)

TypeError: 'method' object is not iterable

I need both of these columns as lists. So, can someone explain to me please what went wrong?

  • 5
    `df[-7:]['count']`. Column access via `.` is a convenience method and prone to many errors like you've encountered. In this case there's a conflict between the method `pd.DataFrame().count` and your column name. – ALollz Aug 06 '20 at 15:37
  • 1
    @ALollz thank you very much mu friend, it worked like gangbusters! – José de Castro Aug 06 '20 at 15:45

0 Answers0