Want to learn more? Take the full course at https://learn.datacamp.com/courses/ma... at your own pace. More than a video, you'll learn hands-on coding & quickly apply skills to your daily work.
---
Pandas DataFrames provide several flexible means of indexing into subsets of our data.
Let's start by importing pandas.
We then read in a small DataFrame of sales data.
The simplest indexing style uses square brackets, just as we would use to index Python lists and NumPy arrays.
For example, in the code shown here, we select with left bracket, column label, right bracket first, followed by left bracket, row label, right bracket.
Thus, here we select salt sold in January.
Columns may also be referred to as attributes of the DataFrame if their labels are valid Python identifiers.
Here we select eggs sold in March with df, dot, eggs, left bracket, Mar, right bracket.
A more efficient and more programmatically reusable way of accessing data in a DataFrame is by using accessors.
These include dot loc and dot iloc.
The difference between dot loc and dot iloc accessors is that the former accesses by using labels, the latter using index positions.
Both accessors use left bracket, row specifier, comma, column specifier, right bracket as syntax.
For instance, here we select spam sold in May using df dot loc.
On the other hand, here we select the same entry using dot iloc 4,2.
Remember, lists and array-type structures in Python use zero-based indexing.
When using bracket-indexing without the dot loc or dot iloc accessors, the result returned can be an individual value, a Pandas Series, or a Pandas DataFrame.
To ensure the return value is a DataFrame, use a nested list within square brackets.
As an example, this call uses a list of column labels (salt and eggs) to subselect a DataFrame with those two columns only.
Notice we swapped the order of these two columns (relative to the ordering in the original DataFrame) in the selection.
Use the exercises to get some practice now in basic indexing with dot loc, dot iloc, and with brackets.
#DataCamp #PythonTutorial #ManipulatingDataFrameswithpandas
Sur cette page du site, vous pouvez voir la vidéo en ligne Python Tutorial : Indexing DataFrames durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur DataCamp 22 mars 2020, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 2,189 fois et il a aimé 20 téléspectateurs. Bon visionnage!