0

I am trying to look through a .csv for rows with a value matching "2. Borgere > 65". There are five rows in my .csv where the fist column matches the word, however pandas return an empty DataFarme. I've tried loading up the .csv both in ISO 8859-1 and Latin-1, but same result.

Here's my code:

#LOAD NØGLETAL IN PANDAS
df_noegletal = pd.read_csv("zipfiler/Vaccine_maalgrupper_DB/Noegletal_vacc_daekning.csv", encoding="Latin-1")

#PRINT ROWS MATCHING VALUE
print(df_noegletal[df_noegletal.eq("2. Borgere > 65").any(1)])

Pandas returns the following:

Empty DataFrame
Columns: [Målgruppe, Ansættelsessted, Bopælsregion, Population, Antal førstevaccinerede, Antal færdigvaccinerede, Førstegangs vaccinerede dækning (%), Færdigvaccinerede dækning (%)]
Index: []

Process finished with exit code 0

Even though there are values in my .csv that match "2. Borgere > 65".

This is a screenshot from my .csv

1
  • Are you really sure it matches exactly, including white space? Commented Jun 30, 2021 at 12:12

3 Answers 3

0

Try to access it with the column name.

It's hard to use Norway(?) variables :)

so for example:

df_noegletal = df_noegletal[df_noegletal['Malgruppe'].str.strip == '2. Borgere > 65']
Sign up to request clarification or add additional context in comments.

Comments

0

Your code compares the whole DataFrame with a string, which is obviously not true.

df_noegletal.eq("2. Borgere > 65")

The syntax should be as follows:

df_noegletal[df_noegletal['Målgruppe' == "2. Borgere > 65"]]

Comments

0

The questions has been solved. No cell did indeed match the value. The problem was I had used commas as a seperator when opening the .csv in Excel splitting what was meant to be a single column into two. The actual value of the cell was "2. Borgere > 65, praktisk hjælp og personlig pleje". Thanks everyone.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.