0

for the last line, there's the error, I cannot figure out why there's the attribute error

import pandas as pd

name = pd.read_csv('location', encoding='latin1')
name['Name'] = name['Name'].str.lower()
movie_name = name['Name'].replace(" ", "_")

try:
URL = "https://www.rottentomatoes.com/m/ + movie_name"
except:
  pass

df = URL
df.to_csv('url.csv', index=False)
2
  • 1
    Can you explain more what are you trying to do please, Here you are calling a method "to_csv" which applies to pandas DataFrame but your URL is a string. I think there is a missing instruction. You are missing the call to a REST api with the URLthat will return a DataFrame but in your case it will not do that. Commented May 23, 2022 at 14:42
  • To be clear, edit this question and tell us what you want to do and show what you have tried. If there is an error it should be in the body of the question as formatted text. Also show what debugging steps you have taken. Commented May 26, 2022 at 20:12

1 Answer 1

1

By setting the dataframe df to URL, you make it contain "https://www.rottentomatoes.com/m/ + movie_name". On another note, you have to move the second " symbol to before the + operation to function: "https://www.rottentomatoes.com/m/" + movie_name.

Sign up to request clarification or add additional context in comments.

5 Comments

I am guessing that your indentation of URL = .. is only displayed incorrectly here on Stackoverflow, but please make sure that it is indented once compared to try.
It worked!!!! I am a newbie to python, thanks a loooot!!!
I indented in Jupyter, thanks for reminding me that. I have one more question, I used "replace" but did not work, would you please have a look at it? The code is : movie_name = name['Name'].replace(" ", "_")
You're welcome! :) To fix the issue with the replace method, you have to annotate the strings with an r for regex like so r"<your regex string>" and add a parameter regex=True to tell pandas that you want to use a regex. Without naming the regex parameter this would look like this: replace(r" ", r"_", True).
If the answer helped you, I would appreciate it, if you could accept it here on Stackoverflow to mark the question as resolved.

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.