Python Pandas Tutorial for Absolute Beginners - #2 Dataframe

preview_player
Показать описание
Learn programming in Pandas, a Python Library, 100 seconds at a time in this video for beginners. This is video number 2: Pandas Dataframe.

—————————————————————
Pandas Dataframe
—————————————————————
As mentioned in the previous video, pandas dataframe is a data structure in pandas with two axis
A dataframe has three parts, the columns, the rows and the index
The zero axis is for the rows and the one axis is for the columns
With a data frame you can pick an index from one of the columns and that column will function as an index
So if I have a dataset with employees, I can choose the employee number to be the index, instead of a default set of index numbers, like the one you have with a python list.
A dataframe can be seen as multiple series next to each other
As a matter of fact we can combine multiple series into a dataframe
employee_number = pd.Series([11,12,13,14,15])
employee = pd.Series([‘John’,’jack’,’Jill’,’Joe’,’Judy’])
employee_age = pd.Series([23,34,45,56,65])
employee_years_service = pd.Series([3,4,5,6,9])
Df = pd.DataFrame({
‘Employee Number’ : employee_number,
‘Employee’ : employee,
‘Age’ : employee_age,
‘Years of Service’ : employee_years_service,
})
print(df)
Pandas is used a lot to explore data files or sources.
To see what columns we have available in our datasource we can use the following code.

To get a sample of the data you can use the head or tails function
The head function grabs the first rows. Pass a number to define how many rows the function should grab
And the tail function grabs the last rows and here you also need to define the amount of rows you want to grab
To get a quick statistic summary of your data, use the describe method.
This method includes, the max value, lowest value, amount of rows, etc.
Here we can see for example that the youngest employee is 23 years old and the oldest employee is 65 years old.
To select a specific sample of rows, we slice. The same way we select values in a regular python list. Like this.
print(df[1:3])
The loc method achieves almost the same result. The loc method includes the index number 3.
With the loc method you can also grab rows in a specific column, instead of the whole dataframe like this

In the next video we will use an actual datasource and use pandas to answer some simple questions about the data

————————————————————————

🦁 Who are you?
My name is Raza. I am 30. I am an IT - manager right now, but I’ve been an accountant for the majority of my career.
I’m in love with #Python :)

You can find me here:
—————————————————————————————

Goals for 2021
Training Python hours: 64/1000
Python/Django Projects: 2/30
Subscribers: 2860/10,000

—————————————————————————————-
#100SecondsOfCode
#pythonforbeginners #programming
Рекомендации по теме