How to select a column from a Dataframe in Python?

Posted by Rohit Kumar | Updated on

Want to select a column from a Dataframe in Python? Use the following example.

They are different. df1[(df1['column_x']=='some_value')] is fine if you’re just looking for a single value. The advantage of isin is that you can pass it multiple values. For example: df1.loc[df1['column_x'].isin(['some_value', 'another_value'])]

It’s interesting to see that from a performance perspective, the first method (using ==) actually seems to be significantly slower than the second (using isin):


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers