Data Frame Attributes || Lesson 1.5 || Python for Data Science || Learning Monkey ||

preview_player
Показать описание
Data Frame Attributes
In this class, We discuss Data Frame Attributes.
The reader should have prior knowledge of Data Frame creation. Click here.
Take an example and understand the attributes present in the data frame.
The example data frame is given below.
import pandas as pd
students={'name':['rajesh','suresh','mahesh','j'],'age':[25,35,40,1],'marks':[85.0,45,65,20]}
df=pd.DataFrame(data=students)
print(df)

List of Attributes
Columns Attribute
The columns attribute will give the list of column names of our data frame.
We can use the columns Attribute to display the column names for index values of columns.
Both the examples are shown below.
# columns Attribute

By default data frame is assigned column values 0,1,2..
Based on these values, we can get the column names.
In the above example, we are displaying the column names of indexes 1 and 2.
dtypes Attribute
The dtypes Attribute is used to give the list of column types.
An example of our data frame is given below.
# dtypes Attribute

In our example, the name is shown as a type object, similar to a string in python.
We discuss the panda's data types in our next classes.
The age column is of type integer, and the marks column is of type float.
iloc Attribute
In our previous class, we discussed loc attributes.
The loc attribute is used to access the elements of the data frame.
The same way iloc is used to access the elements of the data frame using index values.
The examples are given below.
# iloc Attribute
print("-------------------")
print("-------------------")

index Attribute
We discussed the columns attribute above. This columns attribute is used to get the column names.
The same way index attribute is used to get the row names.
The examples are shown below.
# index Attribute
import pandas as pd
df = pd.DataFrame([[1, 2], [4, 5], [7, 8]],index=['a', 'c', 'b'],columns=['C1', 'C2'])
print(df)
print("-----------------")

ndim Attribute
The ndim Attribute will display the no of dimensions of the data frame.
The data frame is of 2 dimensions. Because we have rows and columns.
shape Attribute
The shape attribute will give the shape of the data frame. ie number of rows and columns.
The example is shown below.
# shape Attribute

# ndim Attribute

size Attribute
The size attribute will give the number of elements present in the data frame.
# size Attribute

values Attribute
The values attribute is used to take the elements in the data frame.
Values attribute will convert the data into numpy array.
We can take the values in a column.
The elements in a row can be taken and converted to a numpy array.
Examples are given below.
# values Attribute
import pandas as pd
students={'name':['rajesh','suresh','mahesh','j'],'age':[25,35,40,1],'marks':[85.0,45,65,20]}
df=pd.DataFrame(data=students)
print(df)
print("----------------------")

print(x)
print(type(x))
print("----------------------")
y=df["name"].values
print(y)
print(type(y))
print("------------------------")
print(z)
print(type(z))

Link for playlists:

Рекомендации по теме
Комментарии
Автор

Sir in your ml video Amazon mobile data set. if you used NLP in this dataset. Can you tell me how much NLP part is covered. Is it enough to learn only that part?

SonuKumar-vgrz