5-2a Dataframes Column Operations - Instruction
5-2a Dataframes Column Operations - Instruction
Test yourself:
# All statements below should be True
print(sales.shape == (88475, 11))
2. Use the columns.values DataFrame property and print the results. Your result should be a
list of the column names as follows.
4. Select the columns 'Product_line', 'Product_type', 'Product' and save into a product variable.
Use the ‘variable explorer’ to check your result. You also can inspect first 5 rows using the
head() method, and print the results as below. You should have a DataFrame of size (88475, 3).
Head:
Product_line Product_type Product
0 Camping Equipment Cooking Gear TrailChef Deluxe Cook Set
1 Camping Equipment Cooking Gear TrailChef Double Flame
2 Camping Equipment Tents Star Dome
3 Camping Equipment Tents Star Gazer 2
4 Camping Equipment Sleeping Bags Hibernator Lite
Test yourself:
# All statements below should be True
print(product.shape == (88475, 3))
1
https://www.ibm.com/communities/analytics/watson-analytics-blog/sales-products-sample-data/
5. Rename the column 'Product_line' into 'Product_category' in the product DataFrame.
What do you observe? Use the ‘variable explorer’ to check your result. Print the columns’
names and your result should be as follows.
7. Remove (drop) columns 'Product_line', 'Product_type', 'Product' in the sales DataFrame. Use
the columns DataFrame property and print the results as follows. . You should have a
DataFrame of size (88475, 8).
Test yourself:
# All statements below should be True
print(sales.shape == (88475, 8))
8. Now add the product DataFrame to the sales DataFrame. Print the column names and use
the ‘variable explorer’ to check your result: sales should now be a DataFrame of size (88475,
9).
Test yourself:
# All statements below should be True
print(sales.shape == (88475, 9))