re.compile and findall keyerror: 0 I have a question.

Asked 2 years ago, Updated 2 years ago, 35 views

1) Only the title is extracted from the data frame df_movies2 in the figure == movedata
2) Only values in the format (four digits) are taken from the movedata.
3) I want to save this value in a list format.

1) An error occurs in test=p.foundall (moviedata[0]).
2) error keyerror:0
3) Expected: 0 in movedata[0] seems to be a problem with the key value.

1) If it doesn't work, it shouldn't be the first one, but the first one was good at drawing 1995.
2) Moreover, if you print (movied data), it comes out well without data loss. Refer to the image below
3) What's the problem ㅠ <

python pandas

2022-09-21 11:31

1 Answers

I'm replying. I misread the code a little bit, and I put the wrong answer.

moviedata selects only rows whose title is a specific condition in df_movie, and only the 'title' column is imported from pdSeries

However, this movedata is not just a list, but pd.It's a Series so you can have an index. If you look at the printed results, you can see that the index values in the existing data frame remain the same.

moviedata[idx] does not mean that get the first of moviedata but and moviedata data.

In the first loop, movedata[0] is successful because there is data with movedata index 0.

However, after that, there is no data with an index of zero, so a keyerror occurs in movedata[0].

To get the first of the things that have been narrowed down as intended, you need to change it to moviedata.iloc[0].

I'm confused about the concept, try reading the Pandas document.

https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html


2022-09-21 11:31

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.