5. Advance Filtering

file-download
75MB
  1. Display the data of the orders that are either shipped or processing only.

chevron-rightSolutionhashtag
df[df['Order_Status'].isin(['Shipped', 'Processing'])]
df

# Output

Transaction_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	products
0	8691788	37249	Michelle Harrington	Ebony39@gmail.com	1414786801	3959 Amanda Burgs	Dortmund	Berlin	77985	Germany	...	324.086270	Clothing	Nike	Shorts	Excellent	Same-Day	Debit Card	Shipped	5	Cycling shorts
1	2174773	69749	Kelsey Hill	Mark36@gmail.com	6852899987	82072 Dawn Centers	Nottingham	England	99071	UK	...	806.707815	Electronics	Samsung	Tablet	Excellent	Standard	Credit Card	Processing	4	Lenovo Tab
2	6679610	30192	Scott Jensen	Shane85@gmail.com	8362160449	4133 Young Canyon	Geelong	New South Wales	75929	Australia	...	1063.432799	Books	Penguin Books	Children's	Average	Same-Day	Credit Card	Processing	2	Sports equipment
3	7232460	62101	Joseph Miller	Mary34@gmail.com	2776751724	8148 Thomas Creek Suite 100	Edmonton	Ontario	88420	Canada	...	2466.854021	Home Decor	Home Depot	Tools	Excellent	Standard	PayPal	Processing	4	Utility knife
4	4983775	27901	Debra Coleman	Charles30@gmail.com	9098267635	5813 Lori Ports Suite 269	Bristol	England	48704	UK	...	248.553049	Grocery	Nestle	Chocolate	Bad	Standard	Cash	Shipped	1	Chocolate cookies
...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...
293906	4246475	12104	Meagan Ellis	Courtney60@gmail.com	7466353743	389 Todd Path Apt. 159	Townsville	New South Wales	4567	Australia	...	973.962984	Books	Penguin Books	Fiction	Bad	Same-Day	Cash	Processing	1	Historical fiction
293907	1197603	69772	Mathew Beck	Jennifer71@gmail.com	5754304957	52809 Mark Forges	Hanover	Berlin	16852	Germany	...	285.137301	Electronics	Apple	Laptop	Excellent	Same-Day	Cash	Processing	5	LG Gram
293908	7743242	28449	Daniel Lee	Christopher100@gmail.com	9382530370	407 Aaron Crossing Suite 495	Brighton	England	88038	UK	...	182.105285	Clothing	Adidas	Jacket	Average	Express	Cash	Shipped	2	Parka
293909	9301950	45477	Patrick Wilson	Rebecca65@gmail.com	9373222023	3204 Baird Port	Halifax	Ontario	67608	Canada	...	120.834784	Home Decor	IKEA	Furniture	Good	Standard	Cash	Shipped	4	TV stand
293910	2882826	53626	Dustin Merritt	William14@gmail.com	9518926645	143 Amanda Crescent	Tucson	West Virginia	25242	USA	...	2382.233417	Home Decor	Home Depot	Decorations	Average	Same-Day	Cash	Shipped	2	Clocks
118930 rows × 30 columns
  1. Create a new data frame where customer_id works as an index

chevron-rightSolutionhashtag
ndf=df.set_index('Customer_ID')
ndf

# Output

Transaction_ID	Name	Email	Phone	Address	City	State	Zipcode	Country	Age	...	Total_Amount	Product_Category	Product_Brand	Product_Type	Feedback	Shipping_Method	Payment_Method	Order_Status	Ratings	products
Customer_ID																					
37249	8691788	Michelle Harrington	Ebony39@gmail.com	1414786801	3959 Amanda Burgs	Dortmund	Berlin	77985	Germany	21	...	324.086270	Clothing	Nike	Shorts	Excellent	Same-Day	Debit Card	Shipped	5	Cycling shorts
69749	2174773	Kelsey Hill	Mark36@gmail.com	6852899987	82072 Dawn Centers	Nottingham	England	99071	UK	19	...	806.707815	Electronics	Samsung	Tablet	Excellent	Standard	Credit Card	Processing	4	Lenovo Tab
30192	6679610	Scott Jensen	Shane85@gmail.com	8362160449	4133 Young Canyon	Geelong	New South Wales	75929	Australia	48	...	1063.432799	Books	Penguin Books	Children's	Average	Same-Day	Credit Card	Processing	2	Sports equipment
62101	7232460	Joseph Miller	Mary34@gmail.com	2776751724	8148 Thomas Creek Suite 100	Edmonton	Ontario	88420	Canada	56	...	2466.854021	Home Decor	Home Depot	Tools	Excellent	Standard	PayPal	Processing	4	Utility knife
27901	4983775	Debra Coleman	Charles30@gmail.com	9098267635	5813 Lori Ports Suite 269	Bristol	England	48704	UK	22	...	248.553049	Grocery	Nestle	Chocolate	Bad	Standard	Cash	Shipped	1	Chocolate cookies
...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...
12104	4246475	Meagan Ellis	Courtney60@gmail.com	7466353743	389 Todd Path Apt. 159	Townsville	New South Wales	4567	Australia	31	...	973.962984	Books	Penguin Books	Fiction	Bad	Same-Day	Cash	Processing	1	Historical fiction
69772	1197603	Mathew Beck	Jennifer71@gmail.com	5754304957	52809 Mark Forges	Hanover	Berlin	16852	Germany	35	...	285.137301	Electronics	Apple	Laptop	Excellent	Same-Day	Cash	Processing	5	LG Gram
28449	7743242	Daniel Lee	Christopher100@gmail.com	9382530370	407 Aaron Crossing Suite 495	Brighton	England	88038	UK	41	...	182.105285	Clothing	Adidas	Jacket	Average	Express	Cash	Shipped	2	Parka
45477	9301950	Patrick Wilson	Rebecca65@gmail.com	9373222023	3204 Baird Port	Halifax	Ontario	67608	Canada	41	...	120.834784	Home Decor	IKEA	Furniture	Good	Standard	Cash	Shipped	4	TV stand
53626	2882826	Dustin Merritt	William14@gmail.com	9518926645	143 Amanda Crescent	Tucson	West Virginia	25242	USA	28	...	2382.233417	Home Decor	Home Depot	Decorations	Average	Same-Day	Cash	Shipped	2	Clocks
293911 rows × 29 columns
  1. Arrange the above data frame in ascending order.

chevron-rightSolutionhashtag
ndf.sort_index()

# Output

	Transaction_ID	Name	Email	Phone	Address	City	State	Zipcode	Country	Age	...	Total_Amount	Product_Category	Product_Brand	Product_Type	Feedback	Shipping_Method	Payment_Method	Order_Status	Ratings	products
Customer_ID																					
10000	4340470	Thomas Thompson	Christy6@gmail.com	6640432656	719 Kevin Route	San Francisco	Maine	87288	USA	26	...	1498.693271	Clothing	Nike	Shorts	Good	Same-Day	Cash	Delivered	3	Khaki shorts
10000	4759669	Robert Cook	Caroline60@gmail.com	8428883216	232 Lawrence Greens	San Antonio	Nevada	89220	USA	64	...	2683.057011	Electronics	Samsung	Tablet	Average	Express	Debit Card	Pending	2	Amazon Fire Tablet
10000	8180050	John Patterson	Victoria5@gmail.com	6855934982	136 Perkins Street	Phoenix	North Carolina	28468	USA	26	...	429.917804	Grocery	Coca-Cola	Water	Excellent	Same-Day	PayPal	Delivered	5	Sparkling water
10000	8901617	Teresa Cole	Molly61@gmail.com	3057277425	14721 Robert Glen Apt. 663	Hamburg	Berlin	56734	Germany	22	...	395.898272	Home Decor	Bed Bath & Beyond	Bedding	Good	Express	Credit Card	Delivered	4	Quilt
10001	6592641	Miss Kristen Ingram	Robert93@gmail.com	5583788499	825 Kristen Cape	Portsmouth	England	88498	UK	19	...	367.457739	Grocery	Coca-Cola	Soft Drink	Bad	Express	Cash	Delivered	1	Grape soda
...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...
99998	4716191	Krista Hernandez	Susan84@gmail.com	4281239341	51712 Adam Terrace	Chicago	Connecticut	15148	USA	34	...	1138.475755	Grocery	Pepsi	Water	Good	Same-Day	Cash	Delivered	3	Coconut water
99998	4347464	Tyler Jacobs	Eric15@gmail.com	1768479904	21529 Michael Lights	Bonn	Berlin	68768	Germany	59	...	813.776148	Clothing	Zara	Jeans	Bad	Express	Debit Card	Pending	1	Cropped jeans
99998	1092137	Brian Young	Ronnie31@gmail.com	9478917259	062 Mark Locks Apt. 294	Stuttgart	Berlin	42700	Germany	20	...	463.866247	Books	Random House	Non-Fiction	Bad	Express	PayPal	Processing	1	Science
99999	2398254	Michael Henry	Robert27@gmail.com	7385453791	7820 Brendan Field Suite 657	Chicago	Connecticut	47409	USA	20	...	4446.845023	Electronics	Apple	Laptop	Good	Express	PayPal	Processing	4	Samsung Notebook
99999	8452009	Karen Ellis	Jeanne6@gmail.com	5990004447	3988 Holmes Shoal Apt. 449	San Francisco	Maine	12526	USA	26	...	1097.843467	Books	Random House	Non-Fiction	Average	Standard	Cash	Delivered	2	Biography

293911 rows × 29 columns
  1. Display the data of ratings greater than 3 and excellent feedback.

chevron-rightSolutionhashtag
  1. Create a new data frame that has customer id and name as index.

chevron-rightSolutionhashtag
  1. Reset the index of the above data frame and remove the older index.

chevron-rightSolutionhashtag
  1. Make products column as index in the same dataframe and arrange them in descending order.

chevron-rightSolutionhashtag
  1. Change the index of the data frame to city, state, country in the same variable

chevron-rightSolutionhashtag
  1. Make zipcode as a new index, sort it in ascending order and store it in a new variable.

chevron-rightSolutionhashtag
  1. Reset the index of the above data frame in the same variable.

chevron-rightSolutionhashtag

Last updated