Pandas selection iloc loc note

PHOTO EMBED

Thu Oct 07 2021 08:48:22 GMT+0000 (Coordinated Universal Time)

Saved by @QuinnFox12 #chinese #stopwords #convertchitra

# selectdataframe from index from list of int
top_sim = [21, 24622, 32199, 32570, 17463]

top_sim_frame = job_vec.loc[top_simi, : ]
# --------------------

You nedd add () because & has higher precedence than ==:

df3 = df[(df['count'] == '2') & (df['price'] == '100')]
print (df3)
  id count price
0  1     2   100

If need check multiple values use isin:

df4 = df[(df['count'].isin(['2','7'])) & (df['price'].isin(['100', '221']))]
print (df4)
  id count price
0  1     2   100
3  4     7   221

But if check numeric, use:

df3 = df[(df['count'] == 2) & (df['price'] == 100)]
print (df3)

df4 = df[(df['count'].isin([2,7])) & (df['price'].isin([100, 221]))]
print (df4)

content_copyCOPY

https://thispointer.com/select-rows-columns-by-name-or-index-in-dataframe-using-loc-iloc-python-pandas/