Issue
I have a column named "States" with all 50 states as the values and I am attempting to pull certain states to set up in another DataFrame by region. However when i do so and run the new DataFrame I get the the Value Error "ValueError: Lengths must match to compare". This is the cell of the code I am running as well.Snippet of code
Solution
Apparently, in such a case, the equality evaluation is being put to all the array, therefore, since the lengths of the column and the array are different, the error is risen.
You can probably apply the same solution as in this question, which is using the isin
method:
state_data_df[state_data_df["State"].isin(['Maine', 'Massachusetts', ...])]
Answered By - N Pinheiro
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.