import pandas
fileref = open('chart.csv')
f = pandas.read_csv(fileref)
f_set = f[f.year >= 2005]
print(f_set.groupby('y').namefromchart.nunique())
So I know f_set
will print out my y cells with the corresponding years of 2005 through current. What if I want to print out the years 2002 through 2009?
It seems you need add second condition to boolean indexing
:
import pandas as pd
f = pd.read_csv('chart.csv')
f_set = f[(f.year >= 2002) & (f.year < 2010)]
print (f_set.groupby('y').namefromchart.nunique())
Another solution with between
, by default is inclusive :
f_set = f[f.year.between(2002,2009)]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.