Course Content
Introduction to Python for Data Analysis
Introduction to Python for Data Analysis
2. Introduction to Python 2/2
3. Explore Dataset
Data StudyOperations with the FileHow to Explore the DataSorting DataMax, min, mean, medianChallengeGroup DataDive Deeper into Grouping DataGroup Data 2.0Introduction to NumPyPivot TablesRecall Loops.loc FunctionDeal with Several ConditionsChallengeVisualization: First StepsDive Deeper into Visualization
.loc Function
Pandas allows you to set specific conditions on the dataset without an if/else statement and loops. Look at the syntax:
DataFrame.loc[DataFrame['job_title'] == 'Data Scientist'].count()
So inside the .loc[]
function, you just put the condition you need. Here you compare if 'job_title'
is equal to 'Data Scientist'
.
It compares each value of 'job_title'
to the 'Data Scientist'
string.
The ways of creating such conditions are the same as for if
statements; you can use >
, <
, >=
, =<
, ==
with the same meaning.
Everything was clear?
Thanks for your feedback!
Section 3. Chapter 13