You are on page 1of 5

COMPUTER SCIENCE DEPARTMENT

CS0009
FUNDAMENTAL OF ANALYTICS

LAB EXERCISE

1
USING PANDAS

Name of Student: Name of Professor:


ZUNIEGA, Kane Sir Aquino
Nathaniel O.
Data Performed: Date Submitted:
September 13, 2022 September 13, 2022
TASK:

Open any tool in writing Python program.


Follow the given steps in exploring and learning Pandas in Python:

NOTE: Take a screenshot of Steps 4-7.

1. Import the module pandas

import pandas as pd

2. Declare the data set. Either user-defined or from reading cvs file.

#for two-dimensional
mydataset = {
  'cars': ["Toyota", "Mitsubishi", "Honda"],
  'ratings': [1, 3, 5]
}

#for one-dimensional
mydataset = [2, 0, 2, 2]

3. Create the data frame

#for two-dimensional
myvar = pd.DataFrame(mydataset)

#for one-dimensional
myvar = pd.Series(mydataset)

#creating label index


myvar = pd.Series(mydataset, index = ["a", "k", "i"])

#for reading csv file


myvar = pd.read_csv('data.csv')

4. Print the dataset


#for printing the first and last 5 records
print(myvar)

#for printing all the records


print(myvar.to_string()) 

#for printing the first value


print(myvar[0])

#for printing using label index


print(myvar["a"])

#for printing first row using loc attribute


print(myvar.loc[0])

Screenshot here:

5. Verify and print the panda version

print(pd.__version__)

Screenshot here:

6. Verify, print, and modify the maximum returned row

print(pd.options.display.max_rows) 
pd.options.display.max_rows = value
print(pd.options.display.max_rows) 
Screenshot here:

7. Analyzing DataFrame

#for displaying the top 5 rows


print(df.head())

#for displaying the top specified number of rows


print(df.head(10))

#for displaying the last 5 rows


print(df.tail())

#for displaying the last specified number of rows


print(df.tail(10))

#for printing the info about the dataset


print(df.info()) 

Screenshot here:

You might also like