I have a dataframe input_data
. I can't figure out how to select an individual row, based on two conditions. My dataframe looks as follows:
Date Open High Low Close Volume Name
0 2006-01-03 77.76 79.35 77.24 79.11 3117200 ABC
1 2006-01-03 51.70 52.58 51.05 52.58 7825700 DEF
I can select by date alone, or name alone, but get errors with:
print(input_data.loc[(input_data['Date'] == pd.to_datetime('2006-01-03 00:00:00'))and (input_data['Name'] == 'ABC')]).
I've tried to mimic the code from here, here and here but no luck.
print(input_data.loc[input_data['Date'] == pd.to_datetime('2006-01-03 00:00:00')])
print(input_data.loc[input_data['Name'] == 'ABC'])
# Below line doesn't work
print(input_data.loc[(input_data['Date'] == pd.to_datetime('2006-01-03 00:00:00'))and (input_data['Name'] == 'MMM')])
Using the date and 'ABC' I want to end up with:
0 2006-01-03 77.76 79.35 77.24 79.11 3117200 ABC
Simple answers that I can understand are preferred.