Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pandas Help
#1
# 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?
Reply
#2
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
Reply
#3
cannot figure out where i went wrong? any suggestions?
thank you
CliffordHubbard
Reply
#4
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
Reply
#5
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.
Reply
#6
# 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...
Reply
#7
# 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...
Reply
#8
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.
Reply
#9
mojave_homelessness = homelessness[homelessness['state'].isin(canu)]
I hope this is not too late.
Reply
#10
(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)
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020