Display only customer ID, name, email, phone, and address columns of the top 3 rows.
Solution
import pandas as pddf=pd.read_csv('retail_data.csv')df.iloc[0:3,1:6]# this can also be done by df.head(3)[['Customer_ID', 'Name', 'Email', 'Phone', 'Address']]# Output Customer_ID Name Email Phone Address037249 Michelle Harrington Ebony39@gmail.com 14147868013959 Amanda Burgs169749 Kelsey Hill Mark36@gmail.com 685289998782072 Dawn Centers230192 Scott Jensen Shane85@gmail.com 83621604494133 Young Canyon
Display the last 5 rows and first 5 columns of the dataset.
Solution
df.iloc[-5:,0:5]# Output Transaction_ID Customer_ID Name Email Phone293906424647512104 Meagan Ellis Courtney60@gmail.com 7466353743293907119760369772 Mathew Beck Jennifer71@gmail.com 5754304957293908774324228449 Daniel Lee Christopher100@gmail.com 9382530370293909930195045477 Patrick Wilson Rebecca65@gmail.com 9373222023293910288282653626 Dustin Merritt William14@gmail.com 9518926645
Display the last 7 rows and last 7 columns.
Solution
df.iloc[-7:,-7:]# OutputProduct_Type Feedback Shipping_Method Payment_Method Order_Status Ratings products293904 Tablet Average Same-Day Cash Pending 2 Amazon Fire Tablet293905 Shorts Excellent Standard Cash Delivered 4 Chino shorts293906 Fiction Bad Same-Day Cash Processing 1 Historical fiction293907 Laptop Excellent Same-Day Cash Processing 5 LG Gram293908 Jacket Average Express Cash Shipped 2 Parka293909 Furniture Good Standard Cash Shipped 4 TV stand293910 Decorations Average Same-Day Cash Shipped 2 Clocks
Retrieve the first 3 rows
Solution
df.iloc[:3]# OutputTransaction_ID Customer_ID Name Email Phone Address City State Zipcode Country ... Total_Amount Product_Category Product_Brand Product_Type Feedback Shipping_Method Payment_Method Order_Status Ratings products0869178837249 Michelle Harrington Ebony39@gmail.com 14147868013959 Amanda Burgs Dortmund Berlin 77985 Germany ... 324.086270 Clothing Nike Shorts Excellent Same-Day Debit Card Shipped 5 Cycling shorts1217477369749 Kelsey Hill Mark36@gmail.com 685289998782072 Dawn Centers Nottingham England 99071 UK ... 806.707815 Electronics Samsung Tablet Excellent Standard Credit Card Processing 4 Lenovo Tab2667961030192 Scott Jensen Shane85@gmail.com 83621604494133 Young Canyon Geelong New South Wales 75929 Australia ... 1063.432799 Books Penguin Books Children's Average Same-Day Credit Card Processing 2 Sports equipment
Display the rows where the order status is shipped.
Solution
Display the data of Berlin state.
Solution
Display the data for the electronics and clothing category only.
Solution
Display the data of Germany where ratings are between 3-5(inclusive).
Solution
Display the data of Adidas and Nike with excellent feedback.
Solution
Display orders shipped to Canada with a rating of 3 or higher.
Solution
Find orders where the total amount is greater than $1,000, the payment method is "Credit Card," and the product category is "Electronics."
Solution
Find the companies that have excellent feedback for electronics in the American market.