================================================================================
Q1: Create a Series storing 1st 10 even numbers
--------------------------------------------------------------------------------
Code:
even_series = pd.Series([2 * i for i in range(1, 11)])
Output:
0 2
1 4
2 6
3 8
4 10
5 12
6 14
7 16
8 18
9 20
================================================================================
Q1 (i): Top 4 values
--------------------------------------------------------------------------------
Code:
even_series.head(4)
Output:
0 2
1 4
2 6
3 8
================================================================================
Q1 (ii): Check if Series is empty
--------------------------------------------------------------------------------
Code:
even_series.empty
Output:
False
================================================================================
Q1 (iii): Sort the series
--------------------------------------------------------------------------------
Code:
even_series.sort_values()
Output:
0 2
1 4
2 6
3 8
4 10
5 12
6 14
7 16
8 18
9 20
================================================================================
Q1 (iv): Values greater than 6
--------------------------------------------------------------------------------
Code:
even_series[even_series > 6]
Output:
3 8
4 10
5 12
6 14
7 16
8 18
9 20
================================================================================
Q2: Series of Week Names
--------------------------------------------------------------------------------
Code:
week_series = pd.Series(["Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
"Saturday", "Sunday"])
Output:
0 Monday
1 Tuesday
2 Wednesday
3 Thursday
4 Friday
5 Saturday
6 Sunday
================================================================================
Q3: Empty Series
--------------------------------------------------------------------------------
Code:
empty_series = pd.Series(dtype='float64')
Output:
Series([], )
================================================================================
Q4: Monuments and States
--------------------------------------------------------------------------------
Code:
monuments = pd.Series(["Taj Mahal", "Qutub Minar", "Charminar", "Gateway of India"],
index=["Uttar Pradesh", "Delhi", "Telangana", "Maharashtra"])
Output:
Uttar Pradesh Taj Mahal
Delhi Qutub Minar
Telangana Charminar
Maharashtra Gateway of India
================================================================================
Q5: Subject Marks
--------------------------------------------------------------------------------
Code:
subject_marks = pd.Series([75, 78, 82, 86], index=["ENGLISH", "HINDI", "MATHS",
"SCIENCE"])
Output:
ENGLISH 75
HINDI 78
MATHS 82
SCIENCE 86
================================================================================
Q5 (Count): Number of subjects
--------------------------------------------------------------------------------
Code:
subject_marks.count()
Output:
4
================================================================================
Q6: Series from Dictionary
--------------------------------------------------------------------------------
Code:
data_dict = {'a': 0., 'b': 1., 'c': 2}
dict_series = pd.Series(data_dict)
Output:
a 0.0
b 1.0
c 2.0
================================================================================
Q7: Scalar Value Series
--------------------------------------------------------------------------------
Code:
scalar_series = pd.Series([5]*4)
Output:
0 5
1 5
2 5
3 5
================================================================================
DF Q1: Employee Details
--------------------------------------------------------------------------------
Code:
employee_df = pd.DataFrame({
"Empid": [...],
"Ename": [...],
"DOJ": [...]})
Output:
Empid Ename DOJ
0 101 John 2020-01-01
1 102 Priya 2021-03-15
2 103 Amit 2022-06-30
3 104 Rani 2019-08-20
4 105 David 2023-02-01
================================================================================
DF Q2: IPL Player Details
--------------------------------------------------------------------------------
Code:
ipl_df = pd.DataFrame({...})
Output:
player Team Cetegory BidPrize Runs
0 Hardik Mumbai Indians Batsman 13 1000
1 Rahul Kings eleven Batsman 12 2400
2 Virat RCB Batsman 17 3600
3 Rohit Mumbai Indians Batsman 15 3700
4 Jasprit Mumbai Indians Bowler 10 200
================================================================================
DF Q3 (i): Rearranged Columns
--------------------------------------------------------------------------------
Code:
rearranged = df_emp[["Name", "ID", "Dept", "Salary"]]
Output:
Name ID Dept Salary
0 Alice 1 HR 15000
1 Bob 2 IT 12000
2 Charlie 3 Sales 13000
3 David 4 HR 10000
4 Eva 5 IT 14000
================================================================================
DF Q3 (ii): Salary > 12000
--------------------------------------------------------------------------------
Code:
high_salary = df_emp[df_emp["Salary"] > 12000]
Output:
ID Name Salary Dept
0 1 Alice 15000 HR
2 3 Charlie 13000 Sales
4 5 Eva 14000 IT