Wondering how Pandas process the following statement internally please.
import pandas as pd
test = pd.DataFrame({'classNumber': [2, 4], 'center x': [2, 0], 'center y': [4, 4]})
The output of test
:
test.loc[test['classNumber'] == 2, 'center y'] = '5'
The output of test
after operation:
Question: so is this how pandas work here: once it sees that test.loc
has a boolean statement, it will pass it to a function that will return all rows whose test['classNumber'] == 2
then it will assign those rows' column test['center y']
with the new value 5?
CodePudding user response:
Absolutely! The function df.loc[condition, 'column_name']
will locate rows where condition == True
in the column df['column_name']
.