I have a huge csv file and i want to filter out the dataframes with a specific value.
dataf = pd.read_csv('table.txt', sep=',')
dataf[(dataf.Subject_code == '100')]
#print (dataf[(dataf.Subject_code =='100')])
It returns an empty data frame. I get only the headers of the file. I need all the dataframes whose subject code is equal to 100.
Student Subject_code Score 1 100 A 10 500 B 12 100 A 15 100 C
Pandas most likely converts strings representing numbers to numbers (you can find out by doing dataf.info()
and see if the column is numeric or Object
. If it does, you should do equality check against 100
not "100"
.
Use this:
print(dataf[dataf.Subject_code == 100])
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.