Create a DataFrame
Create a DataFrame
Program:
Output:
Question: Add a column 'Marks' to the DataFrame with values 85, 90, and 88.
Program:
Output:
Delete a Column
Question: Delete the 'City' column from the DataFrame.
Program:
Output:
Program:
Output:
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 3 entries, 0 to 2
Data columns (total 3 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 Name 3 non-null object
1 Age 3 non-null int64
2 Marks 3 non-null int64
dtypes: int64(2), object(1)
memory usage: 200.0+ bytes
None
Program:
Output:
Age Marks
count 3.000000 3.000000
mean 24.333333 87.666667
std 2.516611 2.516611
min 22.000000 85.000000
25% 23.000000 86.500000
50% 24.000000 88.000000
75% 25.500000 89.000000
max 27.000000 90.000000
Select a Column
Program:
Output:
0 Alice
1 Bob
2 Charlie
Name: Name, dtype: object
Question: Select the 'Name' and 'Marks' columns from the DataFrame.
Program:
Output:
Name Marks
0 Alice 85
1 Bob 90
2 Charlie 88
Output:
Sort DataFrame
Program:
Output:
Group by Column
Question: Group the DataFrame by 'Name' and calculate the mean of 'Marks'.
Program:
Output:
Name
Alice 85
Bob 90
Charlie 88
Name: Marks, dtype: int64
Merge Two DataFrames
Program
Output: