[英]Pandas- Selecting the columns with specific value
I have a huge csv file and i want to filter out the dataframes with a specific value.我有一个巨大的 csv 文件,我想过滤掉具有特定值的数据帧。
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.
我需要所有主题代码等于 100 的数据帧。
Student Subject_code Score 1 100 A 10 500 B 12 100 A 15 100 C学生 Subject_code 分数 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"
. Pandas 最有可能将表示数字的字符串转换为数字(您可以通过执行
dataf.info()
并查看该列是数字还是Object
。如果是,您应该对100
而不是"100"
进行相等性检查。
Use this:用这个:
print(dataf[dataf.Subject_code == 100])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.