Now when i do query as below:
d2=df.query(‘Subject_Name == Science’)[‘Marks’]
print(d2)
Output: 40
But if i do query as below:
d2=df.query(‘Subject_Name == science’)[‘Marks’]
print(d2)
Output: Series(, Name: Marks, dtype: object)
so How do I query with case sensitivity? Because I am working on large data and not sure weather name will in which case and want match exact string.
Checked with isin, in also. Contains can be used but if two rows contains similar string then it becomes difficult to program which is exact match(for e.g , toast, toaster).
Assuming columns are 0 – 1 and rows are 0 – 3: if you want to return the marks for ‘science’, you simply reference column 0 row 1 for the name and column 1 row 1 for the marks.
Then having normalised your column names you can query:
d2=df.query('Subject_Name == science')['Marks']
So rather than trying to write some flexible (and possibly less
efficient) query, you can make your data all the same, and keep using a
simple query. Simple things are easier to debug and reuse.