Posts: 4
Threads: 1
Joined: Apr 2020
Apr-24-2020, 07:12 PM
(This post was last modified: Apr-24-2020, 07:25 PM by Larz60+.)
# The Mojave Desert states
canu = ["California", "Arizona", "Nevada", "Utah"]
import pandas as pd
# Filter for rows in the Mojave Desert states
mojave_homelessness = homelessness["state"].isin(['canu'])
# See the result
print(mojave_homelessness) Did you call .isin() with the correct argument?
Posts: 59
Threads: 2
Joined: Apr 2020
Is it me or isn't there a question in this post?
- Everybody is a genius. But if you judge a fish by its ability to climb a tree, it will live its whole life believing that it is stupid. Albert Einstein
Posts: 4
Threads: 1
Joined: Apr 2020
cannot figure out where i went wrong? any suggestions?
thank you
CliffordHubbard
Posts: 59
Threads: 2
Joined: Apr 2020
OK, and what went wrong exactly? Do you get an error message? Do you get the wrong output? And if one of those is the case, share something about the error, or explain what kind of output you do expect.
- Everybody is a genius. But if you judge a fish by its ability to climb a tree, it will live its whole life believing that it is stupid. Albert Einstein
Posts: 6,798
Threads: 20
Joined: Feb 2020
mojave_homelessness = homelessness["state"].isin(['canu']) Is definitely wrong if you really want to look for ["California", "Arizona", "Nevada", "Utah"]. As is you are looking for ["canu"].
I don't know if there are other problems. I would suspect you have to create a dataframe somewhere.
In the future start by giving your new post a good name. "Python help" is not very informative when posting to a python help forum. "Pandas help" would be better. "Help with pandas isit" would be a great thing to name your topic.
In the topic text write down what you are trying to do and what problem you are having. If there is an error, include the error text, including the entire traceback.
If you put in some work asking your question you will get faster and better responses.
Posts: 4
Threads: 1
Joined: Apr 2020
# The Mojave Desert states
canu = ["California", "Arizona", "Nevada", "Utah"]
import pandas as pd
# Filter for rows in the Mojave Desert states
mojave_homelessness = homelessness['state'["California", "Arizona", "Nevada", "Utah"]].isin(canu)
# See the result
print(mojave_homelessness) Error: (Track Back Most Recent Call Last)
File "<stdin>", Line 5, in <module>
mojave_homelessness = homelessness['state'["California", "Arizona", "Nevada", "Utah"]].isin(canu)
Type Error: String indices must be integers
I am trying to : Filter homelessness for cases where the USA census state is in the list of Mojave states, canu, assigning to mojave_homelessness
Thank you for the attention. Learning the language and the methods for using this site. Thanks again...
Posts: 4
Threads: 1
Joined: Apr 2020
# The Mojave Desert states
canu = ["California", "Arizona", "Nevada", "Utah"]
import pandas as pd
# Filter for rows in the Mojave Desert states
mojave_homelessness = homelessness['state'["California", "Arizona", "Nevada", "Utah"]].isin(canu)
# See the result
print(mojave_homelessness) Error: (Track Back Most Recent Call Last)
File "<stdin>", Line 5, in <module>
mojave_homelessness = homelessness['state'["California", "Arizona", "Nevada", "Utah"]].isin(canu)
Type Error: String indices must be integers
I am trying to : Filter homelessness for cases where the USA census state is in the list of Mojave states, canu, assigning to mojave_homelessness
Thank you for the attention. Learning the language and the methods for using this site. Thanks again...
Posts: 2,342
Threads: 62
Joined: Sep 2016
I've merged your threads. Please don't create new threads just because you're not getting an answer.
I don't know about Pandas, but your current code is failing for pure-Python reasons:
'state'["California", "Arizona", "Nevada", "Utah"] isn't valid because you're trying to use a string index into a string. Strings can only be indexed with an integer.
Posts: 1
Threads: 0
Joined: Jun 2020
mojave_homelessness = homelessness[homelessness['state'].isin(canu)] I hope this is not too late.
Posts: 1
Threads: 0
Joined: Dec 2020
(Apr-24-2020, 07:12 PM)cliffordhubbard Wrote: # The Mojave Desert states
canu = ["California", "Arizona", "Nevada", "Utah"]
import pandas as pd
# Filter for rows in the Mojave Desert states
mojave_homelessness = homelessness["state"].isin(['canu'])
# See the result
print(mojave_homelessness) Did you call .isin() with the correct argument?
# The Mojave Desert states
canu = ["California", "Arizona", "Nevada", "Utah"]
# Filter for rows in the Mojave Desert states
mojave_homelessness = homelessness[homelessness["state"].isin(canu)]
# See the result
print(mojave_homelessness)
|