# 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?
Is it me or isn't there a question in this post?
cannot figure out where i went wrong? any suggestions?
thank you
CliffordHubbard
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.
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.
# 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...
# 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...
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.
mojave_homelessness = homelessness[homelessness['state'].isin(canu)]
I hope this is not too late.
(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)