0% found this document useful (0 votes)
7 views10 pages

7.3. Dafaframe in Python

A DataFrame is a two-dimensional data structure in pandas that organizes data in rows and columns, allowing for different data types and mutable sizes. It provides various operations such as selecting, adding, and deleting rows and columns. The document includes examples of creating DataFrames using lists and dictionaries, as well as performing common operations on them.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views10 pages

7.3. Dafaframe in Python

A DataFrame is a two-dimensional data structure in pandas that organizes data in rows and columns, allowing for different data types and mutable sizes. It provides various operations such as selecting, adding, and deleting rows and columns. The document includes examples of creating DataFrames using lists and dictionaries, as well as performing common operations on them.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

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
pandas.DataFrame( 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 = pd.DataFrame(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 = pd.DataFrame(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]
df.iloc[1:4]
Operation: addition of rows by .append
Operation: deletion of rows by .drop

You might also like