# Help with Python Data Manipulation with Pandas

Hi,

I am trying to solve this following problem:

# Create indiv_per_10k col as homeless individuals per 10k state pop

homelessness[“indiv_per_10k”] = 10000 *(homelessness[‘individuals’]/homelessness[‘total’])

# Subset rows for indiv_per_10k greater than 20

high_homelessness = homelessness[homelessness.individuals > 10000]

# Sort high_homelessness by descending indiv_per_10k

high_homelessness_srt = high_homelessness.sort_values(by = [‘indiv_per_10k’], ascending = [False])

# From high_homelessness_srt, select the state and indiv_per_10k cols

result = high_homelessness_srt[[‘state’, ‘indiv_per_10k’]]

# See the result

print(result)

I get the following errors:

# Create indiv_per_10k col as homeless individuals per 10k state pop

homelessness[“indiv_per_10k”] = 10000 *(homelessness[‘individuals’]/homelessness[‘total’])

# Subset rows for indiv_per_10k greater than 20

high_homelessness = homelessness[homelessness.individuals > 10000]

# Sort high_homelessness by descending indiv_per_10k

high_homelessness_srt = high_homelessness.sort_values(by = [‘indiv_per_10k’], ascending = [False])

# From high_homelessness_srt, select the state and indiv_per_10k cols

result = high_homelessness_srt[[‘state’, ‘indiv_per_10k’]]

# See the result

print(result)

Can I get some help to resolve this problem? I appreciate your help in advance.

You should change the code like this.

# Create indiv_per_10k col as homeless individuals per 10k state pop

homelessness[“indiv_per_10k”] = 10000 * homelessness[“individuals”] / homelessness[“state_pop”]

# Subset rows for indiv_per_10k greater than 20

high_homelessness = homelessness[homelessness[“indiv_per_10k”]>20]

# Sort high_homelessness by descending indiv_per_10k

high_homelessness_srt = high_homelessness.sort_values([“indiv_per_10k”],ascending = False)

# From high_homelessness_srt, select the state and indiv_per_10k cols

result = high_homelessness_srt[[“state”,“indiv_per_10k”]]

# See the result

print(result)

Here is the solution,

# Create indiv_per_10k col as homeless individuals per 10k state pop

homelessness[“indiv_per_10k”] = 10000 * homelessness[“individuals”] / homelessness[“state_pop”]

# Subset rows for indiv_per_10k greater than 20

high_homelessness = homelessness[homelessness[“indiv_per_10k”] > 20]

# Sort high_homelessness by descending indiv_per_10k

high_homelessness_srt = high_homelessness.sort_values(“indiv_per_10k”, ascending=False)

# From high_homelessness_srt, select the state and indiv_per_10k cols

result = high_homelessness_srt[[“state”, “indiv_per_10k”]]

print(result)