Answers for "select rows in column pandas"

SQL
3

Select rows from a DataFrame based on column values?

#To select rows whose column value equals a scalar, some_value, use ==:
df.loc[df['A'] == 'foo']

#To select rows whose column value is in an iterable, some_values, use isin:
df.loc[df['B'].isin(['one','three'])]

#Combine multiple conditions with &:
df.loc[(df['column_name'] >= A) & (df['column_name'] <= B)]
Posted by: Guest on November-23-2021
2

select rows from dataframe pandas

from pandas import DataFrame

boxes = {'Color': ['Green','Green','Green','Blue','Blue','Red','Red','Red'],
         'Shape': ['Rectangle','Rectangle','Square','Rectangle','Square','Square','Square','Rectangle'],
         'Price': [10,15,5,5,10,15,15,5]
        }

df = DataFrame(boxes, columns= ['Color','Shape','Price'])

select_color = df.loc[df['Color'] == 'Green']
print (select_color)
Posted by: Guest on June-07-2020

Code answers related to "select rows in column pandas"

Code answers related to "SQL"

Browse Popular Code Answers by Language