Skip to content

Commit e2cec72

Browse files
author
pubudu
committed
Lesson df merging
1 parent b6859d7 commit e2cec72

10 files changed

+887
-1188
lines changed

content/0.Numpy_for_bioinformatics.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Lesson plan: Numpy for biological data handling
1+
# Lesson plan
22

33
## Overall objectives
44

content/10.DataFrame_Manipulation.md

+16-44
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
# DataFrame Manipulation & Sorting
22

3-
## Introduction
3+
:::{objectives}
44

5-
**DataFrame Manipulation & Sorting:**
5+
* Demonstrate effective techniques for selecting specific rows and from DataFrames.
6+
* Equip participants with skills to add and remove columns within a DataFrame.
7+
* Implement sorting methods by values, by index, and perform multiple column sorting with custom orders.
8+
:::
69

7-
* Now that we can import data, we need to reshape it for analysis
8-
* Most real-world datasets need significant manipulation before analysis
9-
* Selecting, adding, removing, and reordering data are fundamental skills
10-
* These operations build directly on our understanding of DataFrames as labeled, 2D structures
10+
:::{exercise} Time
11+
20 minutes
12+
:::
1113

1214
:::{discussion}
1315

16+
* Now that we can import data, we need to reshape and manipulate it for analysis
1417
* In real-world data analysis, you'll spend about 80% of your time cleaning and manipulating data, and only 20% on actual analysis
15-
* The skills we're covering today form the backbone of data wrangling in Python
18+
* The skills we're covering in this session form the backbone of data wrangling in Python
1619
* Think of these operations as transforming raw data into analysis-ready information
1720

1821
:::
@@ -296,7 +299,7 @@ Understand the different ways to select data from a DataFrame, including column
296299
* multiple columns
297300
* columns in-place
298301

299-
:::{done}
302+
:::{demo}
300303

301304
```python
302305

@@ -787,45 +790,14 @@ emp004 David 42 Seattle 92000 Tech Tech
787790

788791
:::{discussion}
789792

790-
* "Sorting is essential for both data analysis and presentation."
791-
* "Multi-column sorting is particularly useful for hierarchical data."
792-
* "The `ascending` parameter can be a single boolean or a list of booleans for multi-column sorts."
793-
* "Custom sorting allows for domain-specific ordering beyond simple alphabetical or numerical order."
794-
* "The `inplace=True` parameter can be used to modify the original DataFrame rather than creating a new one."
793+
* Sorting is essential for both data analysis and presentation.
794+
* Multi-column sorting is particularly useful for hierarchical data.
795+
* The `ascending` parameter can be a single boolean or a list of booleans for multi-column sorts.
796+
* Custom sorting allows for domain-specific ordering beyond simple alphabetical or numerical order.
797+
* The `inplace=True` parameter can be used to modify the original DataFrame rather than creating a new one.
795798

796799
:::
797800

798-
**Exercise 3 - Sorting Practice:**
799-
800-
Have students execute:
801-
```python
802-
# Continue with the final inventory DataFrame from Exercise 2
803-
print("Original inventory:")
804-
print(inventory_final)
805-
806-
# 1. Sort the inventory by Category, then by Price (descending) within each category
807-
sorted_by_cat_price = inventory_final.sort_values(['Category', 'Price'],
808-
ascending=[True, False])
809-
print("\n1. Sorted by Category, then by Price (descending):")
810-
print(sorted_by_cat_price)
811-
812-
# 2. Sort the inventory by Value (highest first)
813-
sorted_by_value = inventory_final.sort_values('Value', ascending=False)
814-
print("\n2. Sorted by Total Value (descending):")
815-
print(sorted_by_value)
816-
817-
# 3. Advanced: Create a custom sorting order for Status
818-
# Make 'Available' come before 'Out of Stock'
819-
inventory_final['Status_Coded'] = pd.Categorical(
820-
inventory_final['Status'],
821-
categories=['Available', 'Out of Stock'],
822-
ordered=True
823-
)
824-
sorted_by_status = inventory_final.sort_values('Status_Coded')
825-
print("\n3. Sorted by Status (custom order):")
826-
print(sorted_by_status[['Product_Name', 'Status', 'Status_Coded']])
827-
```
828-
829801
:::{exercise}
830802

831803
**Multiple Column Sorting with Custom Orders:**

0 commit comments

Comments
 (0)