Introduction of the Data Frame
A Data frame is a two-
dimensional data structure,
i.e., data is aligned in a
tabular fashion in rows and
columns. Column label
Features of DataFrame
• Potentially columns are of different
types
• Size – Mutable Data
• Labeled axes (rows and columns)
• Can Perform Arithmetic operations on
rows and columns
Index
Create a Data Frame with pandas
[Link]( data, index, columns, dtype, copy)
Creat using a single list or a list of lists
import pandas as pd
data = [['Alex',10],['Bob',12],['Clarke',13]]
df = [Link](data,columns=['Name','Age'])
print df
Create a DataFrame with a list of dictionaries
import pandas as pd
data = {'Name':['Tom', 'Jack', 'Steve', 'Ricky'],'Age':[28,34,29,42]}
df = [Link](data, index=['rank1','rank2','rank3','rank4'])
print df
Operation: select a column in the data frame
Operation: add a column
Operation: column deletion by .pop
Operation: select row by .loc
Operation: row selection by integer location, .iloc
Operation: select multiple rows by :
df[1:4]
[Link][1:4]
Operation: addition of rows by .append
Operation: deletion of rows by .drop