Skip to main content
Fixed chaining on loc. Updated query to be function call. Added links to docs.
Source Link
Henry Ecker
  • 35.9k
  • 19
  • 48
  • 67

For selecting only specific columns out of multiple columns for a given value in Pandas:

select col_name1, col_name2 from table where column_name = some_value. 

Options loc:

df.loc[df['column_name'] == some_value][[col_name1some_value, [col_name1, col_name2]] 

or query:

df.query['column_name'query('column_name == 'some_value'][[col_name1some_value')[[col_name1, col_name2]] 

For selecting only specific columns out of multiple columns for a given value in Pandas:

select col_name1, col_name2 from table where column_name = some_value. 

Options:

df.loc[df['column_name'] == some_value][[col_name1, col_name2]] 

or

df.query['column_name' == 'some_value'][[col_name1, col_name2]] 

For selecting only specific columns out of multiple columns for a given value in Pandas:

select col_name1, col_name2 from table where column_name = some_value. 

Options loc:

df.loc[df['column_name'] == some_value, [col_name1, col_name2]] 

or query:

df.query('column_name == some_value')[[col_name1, col_name2]] 
Active reading [<https://en.wikipedia.org/wiki/Pandas_%28software%29>].
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134

For selecting only specific columns out of multiple columns for a given value in pandasPandas:

select col_name1, col_name2 from table where column_name = some_value. 

Options:

df.loc[df['column_name'] == some_value][[col_name1, col_name2]] 

or

df.query['column_name' == 'some_value'][[col_name1, col_name2]] 

For selecting only specific columns out of multiple columns for a given value in pandas:

select col_name1, col_name2 from table where column_name = some_value. 

Options:

df.loc[df['column_name'] == some_value][[col_name1, col_name2]] 

or

df.query['column_name' == 'some_value'][[col_name1, col_name2]] 

For selecting only specific columns out of multiple columns for a given value in Pandas:

select col_name1, col_name2 from table where column_name = some_value. 

Options:

df.loc[df['column_name'] == some_value][[col_name1, col_name2]] 

or

df.query['column_name' == 'some_value'][[col_name1, col_name2]] 
deleted 1 character in body
Source Link
firelynx
  • 32.5k
  • 10
  • 94
  • 104

For selecting only specific columns out of multiple columns for a given value in pandas:

select col_name1, col_name2 from table where column_name = some_value. 

Options:

df.loc[df['column_name'] == some_value][[col_name1, col_name2]] 

or

df.query['column_name' == "some_value"'][[col_name1'some_value'][[col_name1, col_name2]] 

For selecting only specific columns out of multiple columns for a given value in pandas:

select col_name1, col_name2 from table where column_name = some_value. 

Options:

df.loc[df['column_name'] == some_value][[col_name1, col_name2]] 

or

df.query['column_name' == "some_value"'][[col_name1, col_name2]] 

For selecting only specific columns out of multiple columns for a given value in pandas:

select col_name1, col_name2 from table where column_name = some_value. 

Options:

df.loc[df['column_name'] == some_value][[col_name1, col_name2]] 

or

df.query['column_name' == 'some_value'][[col_name1, col_name2]] 
Source Link
SP001
  • 591
  • 5
  • 7
Loading