1. DATAFRAME IN PYTHON
Dr. B. Subashini
Assistant Professor of Computer Applications,
V.V.Vanniaperumal College for Women,
Virudhunagar.
2. DATAFRAME
A Data frame is a two-dimensional data structure in which data
are organized in a tabular fashion using rows and columns .
Basic features of data frame are:
• Columns of different data types.
• Size is mutable.
• Data frame has labelled axes for rows and columns.
• Arithmetic operations can be performed on rows and
columns.
3. CREATING A DATA FRAME
A Data frame can be created using the pandas.DataFrame function
from pandas library.
SYNTAX
pandas.DataFrame(data,index,colums)
SAMPLE PROGRAM
4. Create a data frame with 10 rows and 4 columns which has
random values . And perform the following task
a) Specify the index values with difference of 10.
b) Apply sum to data frame.
c) Find the mean of the first column.
d) Find the minimum values in last two rows of data frame.
PROGRAM
5. Create a data frame with 10 rows and 4 columns
which has random values
import numpy as np
import pandas as pd
df=pd.DataFrame(np.random.randn
(10,4))
print(df)
OUTPUT
6. Specify the index values with difference of 10.
print(“RENAMEIND INDEX IN
THE DATAFRAME”)
print(“***************************”)
df2=df.rename(index = lambda x:
(x*10)+10)
print(df2)
OUTPUT
7. Apply sum to data frame
print("APPLYING THE SUM TO
DATAFRAME")
print("*************************")
print("COLUMN WISE SUM")
print("---------------")
print(df.sum(axis=0))
print("ROW WISE SUM")
print("------------")
print(df.sum(axis=1))
OUTPUT
8. Find the mean of the first column
print("FINDING THE MEAN OF
THE FIRST COLUMN")
print("****************************")
print(df[0].mean())
OUTPUT
9. Find the minimum values in last two rows of data frame
print("LAST TWO ROWS IN
DATAFRAME")
print("--------------------------")
print(df.tail(2))
print("THE MINIMUM VALUES")
print("------------------")
print(df.tail(2).min())
OUTPU
T