Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
599 views
in Technique[技术] by (71.8m points)

pandas - The loc function in jupyter does not work for filtering my dataframe

I am pretty new to Jupyter and have importet a data set. That worked fine. Then I wanted to use the loc function to get just one specific value in a specific column. However the loc function simply doesnt work on my Jupyter notebook. I have restarted the whole system - still doesnt work.

Here is an image of the imported data and the data-frame: enter image description here

Then I tried the loc function, however - nothing changes in the dataframe. It actually should filter in the column "Type 1" to just contain values "Fire":

enter image description here

Can someone please help me to get this working? What am I doing wrong?

Thanks.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You made a simple mistake. df prints the whole dataframe just remove the last line

!pip install pandas
import pandas as pd

df = pd.read_csv("/content/pokemon.csv")
df.head(10)
df.loc[df["Type 1"] == "Fire"]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...