Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

choose which columns to display when using Boolean filtering in pandas for python

Is there a way to only show certain columns from a dataset when displaying data after using a Boolean filter?

Here is my code:

birth_year = int(input("What year were you born? "))
if birth_year >= 1980 and birth_year <= 2017:
    print(videogames[videogames['Year'] == birth_year].head(5))

And this is my output:

What year were you born? 2000
Column                                Name Platform  Year         Genre  
Rank                                                                      
133                Pokémon Crystal Version       GB  2000  Role-Playing   
174                       Final Fantasy IX       PS  2000  Role-Playing   
224                               Driver 2       PS  2000        Action   
226               Tony Hawk's Pro Skater 2       PS  2000        Sports   
243     Dragon Quest VII: Warriors of Eden       PS  2000  Role-Playing   

Column         Publisher  NA_Sales  EU_Sales  JP_Sales  Other_Sales  
Rank                                                                  
133             Nintendo      2.55      1.56      1.29         0.99   
174           SquareSoft      1.62      0.77      2.78         0.14   
224                Atari      2.36      2.10      0.02         0.25   
226           Activision      3.05      1.41      0.02         0.20   
243     Enix Corporation      0.20      0.14      4.10         0.02   

Column  Global_Sales  
Rank                  
133             6.39  
174             5.30  
224             4.73  
226             4.68  
243             4.47

Can I have it where it only displays the columns Rank, Name, Year, and Platform?

question from:https://stackoverflow.com/questions/65617818/choose-which-columns-to-display-when-using-boolean-filtering-in-pandas-for-pytho

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

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...