- Write a Pandas program to display the default index and set a column as an Index in a given dataframe.
Test Data:
0 | s001 | V | Alberto Franco | 15/05/2002 | 35 | street1 | t1 |
1 | s002 | V | Gino Mcneill | 17/05/2002 | 32 | street2 | t2 |
2 | s003 | VI | Ryan Parkes | 16/02/1999 | 33 | street3 | t3 |
3 | s001 | VI | Eesha Hinton | 25/09/1998 | 30 | street1 | t4 |
4 | s002 | V | Gino Mcneill | 11/05/2002 | 31 | street2 | t5 |
5 | s004 | VI | David Parkes | 15/09/1997 | 32 | street4 | t6 |
Write a Pandas program to create a multi Index frame using two columns and using an Index and a
column. | |||||||
Test Data: | |||||||
0 | s001 | V | Alberto Franco | 15/05/2002 | 35 | street1 | t1 |
1 | s002 | V | Gino Mcneill | 17/05/2002 | 32 | street2 | t2 |
2 | s003 | VI | Ryan Parkes | 16/02/1999 | 33 | street3 | t3 |
3 | s001 | VI | Eesha Hinton | 25/09/1998 | 30 | street1 | t4 |
4 | s002 | V | Gino Mcneill | 11/05/2002 | 31 | street2 | t5 |
5 | s004 | VI | David Parkes | 15/09/1997 | 32 | street4 | t6 |
Test Data: 0 s001 V Alberto Franco 15/05/2002 35 street1 t1 1 s002 V Gino Mcneill 17/05/2002 32 street2 t2 2 s003 VI Ryan Parkes 16/02/1999 33 street3 t3 3 s001 VI Eesha Hinton 25/09/1998 30 street1 t4 4 s002 V Gino Mcneill 11/05/2002 31 street2 t5 5 s004 VI David Parkes 15/09/1997 32 street4 t6 |
Write a Pandas program to display the default index and set a column as an Index in a given dataframe and then reset the index.
Test Data: 0 s001 V Alberto Franco 15/05/2002 35 street1 t1 1 s002 V Gino Mcneill 17/05/2002 32 street2 t2 2 s003 VI Ryan Parkes 16/02/1999 33 street3 t3 3 s001 VI Eesha Hinton 25/09/1998 30 street1 t4 4 s002 V Gino Mcneill 11/05/2002 31 street2 t5 5 s004 VI David Parkes 15/09/1997 32 street4 t6 |
Write a Pandas program to create an index labels by using 64-bit integers, using floating-point numbers in a given dataframe.
- Write a Pandas program to create a DataFrame using intervals as an index.
- Write a Pandas program to create a dataframe indexing by date and time.
Test Data:
0 | s001 | V | Alberto Franco | 15/05/2002 | 35 street1 | t1 |
1 | s002 | V | Gino Mcneill | 17/05/2002 | 32 street2 | t2 |
2 | s003 | VI | Ryan Parkes | 16/02/1999 | 33 street3 | t3 |
3 | s001 | VI | Eesha Hinton | 25/09/1998 | 30 street1 | t4 |
4 | s002 | V | Gino Mcneill | 11/05/2002 | 31 street2 | t5 |
5 | s004 | VI | David Parkes | 15/09/1997 | 32 street4 | t6 |
Write a Pandas program to create a dataframe and set a title or name of the index column.
Test Data: | |||||||
0 | s001 | V | Alberto Franco | 15/05/2002 | 35 | street1 | t1 |
1 | s002 | V | Gino Mcneill | 17/05/2002 | 32 | street2 | t2 |
2 | s003 | VI | Ryan Parkes | 16/02/1999 | 33 | street3 | t3 |
3 | s001 | VI | Eesha Hinton | 25/09/1998 | 30 | street1 | t4 |
4 | s002 | V | Gino Mcneill | 11/05/2002 | 31 | street2 | t5 |
5 | s004 | VI | David Parkes | 15/09/1997 | 32 | street4 | t6 |
Write a Pandas program to set value in a specific cell in a given dataframe using index.
Test Data: | |||||||
0 | s001 | V | Alberto Franco | 15/05/2002 | 35 | street1 | t1 |
1 | s002 | V | Gino Mcneill | 17/05/2002 | 32 | street2 | t2 |
2 | s003 | VI | Ryan Parkes | 16/02/1999 | 33 | street3 | t3 |
3 | s001 | VI | Eesha Hinton | 25/09/1998 | 30 | street1 | t4 |
4 | s002 | V | Gino Mcneill | 11/05/2002 | 31 | street2 | t5 |
5 | s004 | VI | David Parkes | 15/09/1997 | 32 | street4 | t6 |
Write a Pandas program to convert index of a given dataframe into a column.
Test Data: | |||||||
0 | s001 | V | Alberto Franco | 15/05/2002 | 35 | street1 | t1 |
1 | s002 | V | Gino Mcneill | 17/05/2002 | 32 | street2 | t2 |
2 | s003 | VI | Ryan Parkes | 16/02/1999 | 33 | street3 | t3 |
3 | s001 | VI | Eesha Hinton | 25/09/1998 | 30 | street1 | t4 |
4 | s002 | V | Gino Mcneill | 11/05/2002 | 31 | street2 | t5 |
5 | s004 | VI | David Parkes | 15/09/1997 | 32 | street4 | t6 |
- Write a Pandas program to convert 1st and 3rd levels in the index into columns from a multiple level of index frame of a given dataframe.
Test Data:
0 | s001 | V Alberto Franco | 15/05/2002 | 35 street1 | t1 |
1 | s002 | V Gino Mcneill | 17/05/2002 | 32 street2 | t2 |
2 | s003 | VI Ryan Parkes | 16/02/1999 | 33 street3 | t3 |
3 | s001 | VI Eesha Hinton | 25/09/1998 | 30 street1 | t4 |
4 | s002 | V | Gino Mcneill | 11/05/2002 | 31 street2 | t5 |
5 | s004 | VI | David Parkes | 15/09/1997 | 32 street4 | t6 |
- Write a Pandas program to check if a specified value exists in single and multiple column index dataframe.
![]()
Test Data:
0 | s001 | V | Alberto Franco | 15/05/2002 | 35 street1 | t1 |
1 | s002 | V | Gino Mcneill | 17/05/2002 | 32 street2 | t2 |
2 | s003 | VI | Ryan Parkes | 16/02/1999 | 33 street3 | t3 |
3 | s001 | VI | Eesha Hinton | 25/09/1998 | 30 street1 | t4 |
4 | s002 | V | Gino Mcneill | 11/05/2002 | 31 street2 | t5 |
5 | s004 | VI | David Parkes | 15/09/1997 | 32 street4 | t6 |
Write a Pandas program to construct a series using the MultiIndex levels as the column and index.
Write a Pandas program to construct a DataFrame using the MultiIndex levels as the column and index.
- Write a Pandas program to extract a single row, rows and a specific value from a MultiIndex levels DataFrame.
- Write a Pandas program to rename names of columns and specific labels of the Main Index of the MultiIndex dataframe.
- Write a Pandas program to sort a MultiIndex of a DataFrame. Also sort on various levels of index.
- Write a Pandas program to extract elements in the given positional indices along an axis of a dataframe.
- Write a Pandas program to get the index of an element of a given Series.
- Write a Pandas program to select a specific row of given series/dataframe by integer index.
Test Data:
0 | s001 | V | Alberto Franco | 15/05/2002 | 35 | street1 | t1 |
1 | s002 | V | Gino Mcneill | 17/05/2002 | 32 | street2 | t2 |
2 | s003 | VI | Ryan Parkes | 16/02/1999 | 33 | street3 | t3 |
3 | s001 | VI | Eesha Hinton | 25/09/1998 | 30 | street1 | t4 |
4 | s002 | V | Gino Mcneill | 11/05/2002 | 31 | street2 | t5 |
5 | s004 | VI | David Parkes | 15/09/1997 | 32 | street4 | t6 |
Write a Pandas program to find the indexes of rows of a specified value of a given column in a
DataFrame. | |||||||
Test Data: | |||||||
0 | s001 | V | Alberto Franco | 15/05/2002 | 35 | street1 | t1 |
1 | s002 | V | Gino Mcneill | 17/05/2002 | 32 | street2 | t2 |
2 | s003 | VI | Ryan Parkes | 16/02/1999 | 33 | street3 | t3 |
3 | s001 | VI | Eesha Hinton | 25/09/1998 | 30 | street1 | t4 |
4 | s002 | V | Gino Mcneill | 11/05/2002 | 31 | street2 | t5 |
5 | s004 | VI | David Parkes | 15/09/1997 | 32 | street4 | t6 |
Write a Pandas program to drop a index level from a multi-level column index of a dataframe.
Write a Pandas program to insert a column at a specific index in a given DataFrame.
- Write a Pandas program to print a DataFrame without index.
- Write a Pandas program to find integer index of rows with missing data in a given dataframe.
- Write a Pandas program to start index with different value rather than 0 in a given DataFrame.
- Write a Pandas program to select rows by filtering on one or more column(s) in a multi-index dataframe.
Merging & Joining
- Write a Pandas program to join the two given dataframes along rows and assign all data.
Test Data:
student_data1:
student_id name marks
- S1 Danniella Fenton 200
- S2 Ryder Storey 210
- S3 Bryce Jensen 190
- S4 Ed Bernal 222
- S5 Kwame Morin 199
student_data2:
student_id name marks
- S4 Scarlette Fisher 201
- S5 Carla Williamson 200
S6 Dante Morse 198
- S7 Kaiser William 219
- S8 Madeeha Preston 201
Write a Pandas program to join the two given dataframes along columns and assign all data.
Test Data:
student_data1:
student_id name marks
0 | S1 | Danniella | Fenton | 200 |
1 | S2 | Ryder | Storey | 210 |
2 | S3 | Bryce | Jensen | 190 |
3 | S4 | Ed | Bernal | 222 |
4 | S5 | Kwame Morin | 199 | |
student_data2: student_id name marks | ||||
0 | S4 | Scarlette Fisher | 201 | |
1 | S5 | Carla Williamson | 200 | |
2 | S6 | Dante Morse | 198 | |
3 | S7 | Kaiser William | 219 | |
4 | S8 | Madeeha Preston | 201 |
Write a Pandas program to append rows to an existing DataFrame and display the combined data.
Test Data:
tudent_data1
student_id name marks
- S1 Danniella Fenton 200
- S2 Ryder Storey 210
- S3 Bryce Jensen 190
- S4 Ed Bernal 222
- S5 Kwame Morin 199
New Row(s)
student_id S6
name Scarlette Fisher
marks 205
dtype: object
- Write a Pandas program to append a list of dictioneries or series to a existing DataFrame and display the combined data.
Test Data:
student_id | name | marks |
0 S1 | Danniella Fenton | 200 |
1 S2 | Ryder Storey | 210 |
2 S3 | Bryce Jensen | 190 |
3 S4 | Ed Bernal | 222 |
4 S5 | Kwame Morin | 199 |
Dictionary: | ||
student_id | S6 | |
name | Scarlette Fisher | |
marks dtype: object | 205 |
Write a Pandas program to join the two given dataframes along rows and merge with another dataframe along the common column id.
- Write a Pandas program to join the two dataframes using the common column of both dataframes.
Test Data:
student_data1:
student_id name marks
0 | S1 | Danniella Fenton 200 |
1 | S2 | Ryder Storey 210 |
2 | S3 | Bryce Jensen 190 |
3 | S4 | Ed Bernal | 222 |
4 | S5 | Kwame Morin | 199 |
student_data2: student_id name marks | |||
0 | S4 | Scarlette Fisher | 201 |
1 | S5 | Carla Williamson | 200 |
2 | S6 | Dante Morse | 198 |
3 | S7 | Kaiser William | 219 |
4 | S8 | Madeeha Preston | 201 |
Write a Pandas program to join the two dataframes with matching records from both sides where available.
Test Data:
student_data1:
student_id name marks
- S1 Danniella Fenton 200
- S2 Ryder Storey 210
- S3 Bryce Jensen 190
- S4 Ed Bernal 222
- S5 Kwame Morin 199
student_data2:
student_id name marks
- S4 Scarlette Fisher 201
- S5 Carla Williamson 200
- S6 Dante Morse 198
- S7 Kaiser William 219
- S8 Madeeha Preston 201
Write a Pandas program to join (left join) the two dataframes using keys from left dataframe only.
Test Data:
data1:
key1 key2 P Q 0 K0 K0 P0 Q0
- K0 K1 P1 Q1
- K1 K0 P2 Q2
- K2 K1 P3 Q3
data2:
key1 key2 R S 0 K0 K0 R0 S0
- K1 K0 R1 S1
- K1 K0 R2 S2
- K2 K0 R3 S3
- Write a Pandas program to join two dataframes using keys from right dataframe only.
Test Data:
data1:
key1 key2 P Q 0 K0 K0 P0 Q0
- K0 K1 P1 Q1
- K1 K0 P2 Q2
- K2 K1 P3 Q3
data2: | |||
key1 | key2 | R | S |
0 K0 | K0 | R0 | S0 |
1 K1 | K0 | R1 | S1 |
2 K1 | K0 | R2 | S2 |
3 K2 | K0 | R3 | S3 |
Write a Pandas program to merge two given datasets using multiple join keys.
Test Data:
data1:
key1 key2 P Q 0 K0 K0 P0 Q0
- K0 K1 P1 Q1
- K1 K0 P2 Q2
- K2 K1 P3 Q3
data2:
key1 key2 R S 0 K0 K0 R0 S0
- K1 K0 R1 S1
- K1 K0 R2 S2
- K2 K0 R3 S3
Write a Pandas program to create a new DataFrame based on existing series, using specified argument and override the existing columns names.
Write a Pandas program to create a combination from two dataframes where a column id combination appears more than once in both dataframes.
Test Data:
data1:
key1 key2 P Q 0 K0 K0 P0 Q0
- K0 K1 P1 Q1
- K1 K0 P2 Q2
- K2 K1 P3 Q3
data2:
key1 key2 R S 0 K0 K0 R0 S0
- K1 K0 R1 S1
- K1 K0 R2 S2
- K2 K0 R3 S3
- Write a Pandas program to combine the columns of two potentially differently-indexed DataFrames into a single result DataFrame.
Test Data:
data1:
A B
K0 A0 B0
K1 A1 B1
K2 A2 B2
data2:
C D
K0 C0 D0
K2 C2 D2
K3 C3 D3
Write a Pandas program to merge two given dataframes with different columns.
Test Data:
data1:
key1 key2 P Q 0 K0 K0 P0 Q0
- K0 K1 P1 Q1
- K1 K0 P2 Q2
- K2 K1 P3 Q3
data2:
key1 key2 R S 0 K0 K0 R0 S0
- K1 K0 R1 S1
- K1 K0 R2 S2
- K2 K0 R3 S3
Write a Pandas program to Combine two DataFrame objects by filling null values in one DataFrame with non-null values from other DataFrame.
Test Data:
Original DataFrames: A B
0 NaN 3
1 0.0 4
2 NaN 5 A B
0 1 3.0
1 1 NaN
2 3 3.0