1
        a= []
        for item in soup2.findAll("div", class_='x'):
            where_to_watch = item.find_all('b')
            watch_at.append(x)
            
        dataFrame = pd.DataFrame(data = a)
        dataFrame.to_excel('x.xlsx')
        print(dataFrame)

Hello Guys How can i add "text" when the value is none? or maybe add NAN value...

4
  • show how watch_at look like? Commented Jan 28, 2023 at 14:48
  • @RomanPerekhrest empty lists? watch_at = [] Commented Jan 28, 2023 at 14:55
  • If where-to_watch is None then it will be added to the List watch_at as None and then will appear in the DataFrame as NaN. So where is the problem? Commented Jan 28, 2023 at 15:07
  • Fixed it already i just added the new = dataFrame.fillna("NO DATA") fill na method Commented Jan 28, 2023 at 15:19

1 Answer 1

1

I think you could use fillna() method to achieve your goal. It would look like that:

dataFrame = dataFrame.fillna("text")
dataFrame.to_excel('watch.xlsx')

Also there's a function called isna(). You could use it like that:

if pd.isna(where_to_watch):
    where_to_watch = "text"
watch_at.append(where_to_watch)
dataFrame.to_excel('watch.xlsx')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.