0% found this document useful (0 votes)
3 views

Python Class - 22

The document provides an introduction to the Pandas library in Python, emphasizing its use for data analysis. It includes examples of creating data frames and series, as well as manipulating data using various methods. The content is aimed at teaching Python programming through practical coding examples in PyCharm.

Uploaded by

nazar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Python Class - 22

The document provides an introduction to the Pandas library in Python, emphasizing its use for data analysis. It includes examples of creating data frames and series, as well as manipulating data using various methods. The content is aimed at teaching Python programming through practical coding examples in PyCharm.

Uploaded by

nazar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

TECHMIND INFOTECH

Computer Education and Project Training Centre


(A Government Approved Institution)
Sri Ram Towers 2nd Floor, Santhanathapuram 6th Street, Pudukkottai
Cell: 7293 52 7293 Email: [email protected]
PYTHON PROGRAMMING – CLASS 22

WORKING WITH PANDAS LIBRARY USING PYCHARM


Note:
Install the panda library in Pycharm tool.
Introduction:

Pandas is a Python library.

Pandas is used to analyze data.

CREATING DATA FRAME SET


Example:

import pandas as pd
mydataset = {
'cars': ["BMW", "Volvo", "Ford"],
'passings': [3, 7, 2]
}
myvar = pd.DataFrame(mydataset)
print(myvar)
Output:
cars passings
0 BMW 3
1 Volvo 7
2 Ford 2

CREATING DATA SERIES


Example:
import pandas as pd
a = [1, 7, 2]
myvar = pd.Series(a)
print(myvar)
Output:
0 1
1 7
2 2
dtype: int64

CREATING LABLES

Example:
import pandas as pd
a = [1, 7, 2]
myvar = pd.Series(a, index = ["x", "y", "z"])
print(myvar)
Output:
x 1
y 7
z 2
dtype: int64

Example 2:
import pandas as pd
a = [1, 7, 2]
myvar = pd.Series(a, index = ["x", "y", "z"])
print(myvar["y"])
Output:
7
;
CREATING SERIES FROM DICITIONARY

Example 1:
import pandas as pd
calories = {"day1": 420, "day2": 380, "day3": 390}
myvar = pd.Series(calories)
print(myvar)

Output:
day1 420
day2 380
day3 390
dtype: int64
Example 2:

import pandas as pd

calories = {"day1": 420, "day2": 380, "day3": 390}

myvar = pd.Series(calories, index = ["day1", "day2"])

print(myvar)

Output:
day1 420
day2 380
dtype: int64

Example 3:

import pandas as pd

data = {
"calories": [420, 380, 390],
"duration": [50, 40, 45]
}

#load data into a DataFrame object:


df = pd.DataFrame(data)

print(df.loc[0])

Output:
calories 420
duration 50
Name: 0, dtype: int64
Example 4:

import pandas as pd

data = {
"calories": [420, 380, 390],
"duration": [50, 40, 45]
}

df = pd.DataFrame(data, index = ["day1", "day2", "day3"])

print(df)

Output:

calories duration
day1 420 50
day2 380 40
day3 390 45

Example 5:

import pandas as pd

data = {
"calories": [420, 380, 390],
"duration": [50, 40, 45]
}

df = pd.DataFrame(data, index = ["day1", "day2", "day3"])

print(df.loc["day2"])

Output:
calories 380
duration 40
Name: day2, dtype: int64

You might also like