Pandas Lab Assignment Work-2
Pandas Lab Assignment Work-2
1. Create a Pandas Series from the list: [5, 10, 15, 20, 25].
2. Assign custom indices: ['a', 'b', 'c', 'd', 'e'].
3. Extract the element at index 'c'.
4. Extract the first three elements of the Series.
5. Multiply all values in the Series by 2 and display the result.
2) Write a Pandas program to add, subtract, multiple and divide two Pandas Series.
Sample Series: [2, 4, 6, 8, 10], [1, 3, 5, 7, 9]
3) Write a Pandas program to compare the elements of the two Pandas Series.
Sample Series: [2, 4, 6, 8, 10], [1, 3, 5, 7, 10]
Sample Output:
Original Data Series:
A 1
B 2
C 3
D 4
E 5
7) Write a Pandas program to create the mean and standard deviation of the
data of a given Series.
8) Write a Pandas program to create a dataframe from a dictionary and display it.
Sample data: {'X':[78,85,96,80,86], 'Y':[84,94,89,83,86],'Z':[86,97,96,72,83]}
b) Write a Pandas program to select the 'name' and 'score' columns from the
following DataFrame
c) Write a Pandas program to select the rows where the number of attempts in
the examination is greater than 2.
d)Write a Pandas program to select the rows where the score is greater than 60.
data = {
Filter and display all rows where Age is greater than 25.
Display all employees with a Salary greater than 60,000.
Display all employees whose Age is between 25 and 35.
11) Write a Pandas program to select rows where the value in the 'A' column is
greater than 4.
12) Write a Pandas program to select only the 'X' and 'Y' columns from the
DataFrame.
13) Write a Pandas program to use Boolean indexing to select rows where
column 'x' > 6.
14) Write a Pandas program to select the first three rows using iloc.
15) Write a Pandas program to use .loc to select rows based on a condition
17) Write a Pandas program that performs a left join of two DataFrames.
18) Write a Pandas program to merge DataFrames and rename columns after
merge.
.str.contains("X") df[df["City"].str.contains("New")]
Checks if the string
Function Description Example
contains "X"
Filters based on
.str.len() df[df["Name"].str.len() > 5]
string length
Example:-
import pandas as pd
data = {
"City": ["New York", "Los Angeles", "Chicago", "New Delhi", "New Orleans"]
df = pd.DataFrame(data)
1.Starts With (startswith())
df[df["Name"].str.startswith("A")]
df[df["Email"].str.endswith(".com")]
import pandas as pd
data = {
"Name":[],
"Age": [],
"Salary": [],
"Department":[]
df = pd.DataFrame(data)
Find employees who are older than 30 AND earn more than 60,000.
Find employees who are in HR OR have a Salary above 70,000.
Use .loc[] to retrieve all employees whose Age is between 25 and 35.
Use .loc[] to select employees in the IT department and display only "Name" and "Salary".