-1

I am trying to iterate through the rows of a CSV file where I saved a list of my followers, with the data associated to the subscribing event and a flag that specifies if I already unsubscribed from the specific follower.

Here is an example of the file:

List of follower with data of subscription and unsubscribe flag

Right now I am trying to build a loop in that way:

I try to calculate a new variable time_d that gives me the number of days since the subscription. Then I will do an if statement in which I ask:

  1. if the subscription occurred more than 7 days ago AND my flag_unsubscribe = 'NO' then try etc.
df = pd.read_csv("follower.csv",parse_dates=[1])
for row in df.itertuples():
    time_d = pd.Timestamp("today") - row[2]
    print(time_d)
    converted_time_d = pd.DataFrame([time_d]).apply(np.float32)
    print(converted_time_d," - ",row[3])
    #if all((all(converted_time_d)>=7) and all(str(row[3]))!='1.0'):
    if all((all(converted_time_d)<=7) and str(row[3])=="NO"):
        try:

Right now, I am receiving this error:

Traceback (most recent call last):
  File "C:\Users\XXX\OneDrive\Desktop\XXX\unfollow_by_profile.py", line 26, in <module>
    if all((all(converted_time_d)<=7) and str(row[3])=="NO"):
TypeError: 'bool' object is not iterable

Can someone help me? I tried to look on a similar post, but I did not find anything that could fix the problem.

Mario MateaČ™
  • 638
  • 7
  • 25

1 Answers1

0

all() accepting Iterable and returns bool. The problem that you trying to pass to all() non-iterable type. If you want to check multiple conditions in all() put conditions to list or tuple and pass it to function:

if all([condition1, condition2]): ...

Maybe you need:

if all([converted_time_d <= 7, row[3] == "NO"]): ...

But in your case with only two conditions maybe it will be enough to use simple and?

if converted_time_d <= 7 and row[3] == "NO": ...

and I think you don't need to use str(row[3]) but just row[3] because there is nothing you can convert to string type from non-string type to get "NO" value :) only if you have bytes type.

toberon
  • 31
  • 2