PDA Assignments
  • Python For Data Analytics
    • 1.Python
      • 1.Python Documents
        • 1.Data Types
        • 2.Variables In Python
        • 3.Operators In Python
        • 4.User Input In Python
        • 5.TypeCasting In Python
        • 6.Strings In Python
        • 7.Conditional Statements In Python
        • 8.Branching using Conditional Statements and Loops in Python
        • 9.Lists In Python
        • 10.Sets In Python
        • 11.Tuples In Python
        • 12.Dictionary In Python
        • 13.Functions In Python
        • 14.File Handling In Python
        • 15.Numerical Computing with Python and Numpy
      • 2.Python Assignments
        • Data Type & Variables
        • Operators Assignment
        • User Input & Type Casting
        • Functions- Basic Assignments
        • String Assignments
          • String CheatSheet
        • Conditional Statements Assignments
        • Loops Assignments
        • List Assignments
          • List Cheatsheet
        • Set Assignments
          • Sets Cheatsheet
        • Dictionary Assignments
          • Dictionary Cheatsheet
        • Function Assignments
        • Functions used in Python
      • 3.Python Projects
        • Employee Management System
        • Hamming distance
        • Webscraping With Python
          • Introduction To Web Scraping
          • Importing Necessary Libraries
          • Basic Introduction To HTML
          • Introduction To BeautifulSoup
          • Flipkart Web Scraping
            • Scraping Step By Step
        • Retail Sales Analysis
        • Guess the Word Game
        • Data Collection Through APIs
        • To-Do List Manager
        • Atm-functionalities(nested if)
        • Distribution of Cards(List & Nested for)
        • Guess the Number Game
      • 4.Python + SQL Projects
        • Bookstore Management System
    • 2.Data Analytics
      • 1.Pandas
        • 1.Pandas Documents
          • 1.Introduction To Pandas
          • Reading and Loading Different Data
          • 2.Indexing and Slicing In Pandas
          • 3.Joining In Pandas
          • 4.Missing Values In Pandas
          • 5.Outliers In Pandas
          • 6.Aggregating Data
          • 7.DateTime In Pandas
          • 8.Validation In Pandas
          • 9.Fetching Data From SQL
          • 10. Automation In Pandas
          • 11.Matplotlib - Data Visualization
          • 12. Seaborn - Data Visualization
          • 13. Required Files
        • 3.Pandas Projects
          • Retail Sales Analysis
            • Retail Sales Step By Step
          • IMDB - Dataset Analysis - Basic
        • 2. Pandas Assignments
          • 1. Reading and Loading the Data
          • 2. Data frame Functions and Properties
          • 3. Series - Basic Operations
          • 4. Filtering in Pandas
          • 5. Advance Filtering
          • 6. Aggregate Functions & Groupby
          • 7. Pivot Tables
          • 8. Datetime
          • 9. String Functions
Powered by GitBook
On this page
  1. Python For Data Analytics
  2. 2.Data Analytics
  3. 1.Pandas
  4. 2. Pandas Assignments

5. Advance Filtering

Previous4. Filtering in PandasNext6. Aggregate Functions & Groupby

Last updated 6 months ago

  1. Display the data of the orders that are either shipped or processing only.

Solution
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

Solution
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.

Solution
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.

Solution
ndf=df[(df['Ratings'] > 3) & (df['Feedback'] == 'Excellent')]
ndf

# 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
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
9	4926148	31878	Lori Bell	Jessica33@gmail.com	6004895059	6225 William Lodge	Cologne	Berlin	64317	Germany	...	3976.112295	Home Decor	Home Depot	Decorations	Excellent	Standard	Cash	Delivered	4	Candles
13	3217461	74671	Felicia Brown	Laura72@gmail.com	8869644441	381 Richard Plaza	Portsmouth	England	32061	UK	...	3157.353142	Grocery	Nestle	Snacks	Excellent	Express	PayPal	Delivered	4	Fruit snacks
...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...
293897	5781099	41133	Cheryl Collins	Tina76@gmail.com	6851286333	6806 Buchanan Place Apt. 569	Nuremberg	Berlin	91049	Germany	...	102.938408	Clothing	Adidas	T-shirt	Excellent	Standard	Cash	Processing	4	Scoop neck tee
293900	8032917	31242	Danielle Anderson	Todd67@gmail.com	3445479425	369 Barnes Tunnel	San Antonio	Florida	32598	USA	...	413.734856	Electronics	Samsung	Tablet	Excellent	Same-Day	Cash	Shipped	5	iPad
293903	8961631	79479	Jason Welch	Jason36@gmail.com	6279294104	764 Garcia Flat	Hamilton	Ontario	61218	Canada	...	2659.976987	Home Decor	Home Depot	Tools	Excellent	Express	Cash	Pending	5	Level
293905	4833982	94117	Kara Hart	Tammy37@gmail.com	7108672468	872 Robinson Harbors Apt. 328	Charlotte	Missouri	65301	USA	...	2362.120301	Clothing	Nike	Shorts	Excellent	Standard	Cash	Delivered	4	Chino shorts
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
98016 rows × 30 columns
  1. Create a new data frame that has customer id and name as index.

Solution
ndf=df.set_index(['Customer_ID', 'Name'])
ndf

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

Solution
ndf.reset_index(inplace=True,drop=True)
ndf

# Output

City	State	Country	Transaction_ID	Email	Phone	Address	Zipcode	Age	Gender	...	Total_Amount	Product_Category	Product_Brand	Product_Type	Feedback	Shipping_Method	Payment_Method	Order_Status	Ratings	products
0	Dortmund	Berlin	Germany	8691788	Ebony39@gmail.com	1414786801	3959 Amanda Burgs	77985	21	Male	...	324.086270	Clothing	Nike	Shorts	Excellent	Same-Day	Debit Card	Shipped	5	Cycling shorts
1	Nottingham	England	UK	2174773	Mark36@gmail.com	6852899987	82072 Dawn Centers	99071	19	Female	...	806.707815	Electronics	Samsung	Tablet	Excellent	Standard	Credit Card	Processing	4	Lenovo Tab
2	Geelong	New South Wales	Australia	6679610	Shane85@gmail.com	8362160449	4133 Young Canyon	75929	48	Male	...	1063.432799	Books	Penguin Books	Children's	Average	Same-Day	Credit Card	Processing	2	Sports equipment
3	Edmonton	Ontario	Canada	7232460	Mary34@gmail.com	2776751724	8148 Thomas Creek Suite 100	88420	56	Male	...	2466.854021	Home Decor	Home Depot	Tools	Excellent	Standard	PayPal	Processing	4	Utility knife
4	Bristol	England	UK	4983775	Charles30@gmail.com	9098267635	5813 Lori Ports Suite 269	48704	22	Male	...	248.553049	Grocery	Nestle	Chocolate	Bad	Standard	Cash	Shipped	1	Chocolate cookies
...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...
293906	Townsville	New South Wales	Australia	4246475	Courtney60@gmail.com	7466353743	389 Todd Path Apt. 159	4567	31	Male	...	973.962984	Books	Penguin Books	Fiction	Bad	Same-Day	Cash	Processing	1	Historical fiction
293907	Hanover	Berlin	Germany	1197603	Jennifer71@gmail.com	5754304957	52809 Mark Forges	16852	35	Female	...	285.137301	Electronics	Apple	Laptop	Excellent	Same-Day	Cash	Processing	5	LG Gram
293908	Brighton	England	UK	7743242	Christopher100@gmail.com	9382530370	407 Aaron Crossing Suite 495	88038	41	Male	...	182.105285	Clothing	Adidas	Jacket	Average	Express	Cash	Shipped	2	Parka
293909	Halifax	Ontario	Canada	9301950	Rebecca65@gmail.com	9373222023	3204 Baird Port	67608	41	Male	...	120.834784	Home Decor	IKEA	Furniture	Good	Standard	Cash	Shipped	4	TV stand
293910	Tucson	West Virginia	USA	2882826	William14@gmail.com	9518926645	143 Amanda Crescent	25242	28	Female	...	2382.233417	Home Decor	Home Depot	Decorations	Average	Same-Day	Cash	Shipped	2	Clocks
293911 rows × 28 columns
  1. Make products column as index in the same dataframe and arrange them in descending order.

Solution
df.set_index('products',inplace=True)
df.sort_index(ascending=False,inplace=True)
df


# Output

    Transaction_ID	Customer_ID	Name	Email	Phone	Address	City	State	Zipcode	Country	...	Amount	Total_Amount	Product_Category	Product_Brand	Product_Type	Feedback	Shipping_Method	Payment_Method	Order_Status	Ratings
products																					
iPhone	9709387	57737	Sarah Avila	April33@gmail.com	1242148962	721 Daniel Lake	Portsmouth	England	2804	UK	...	285.091529	1425.457643	Electronics	Samsung	Smartphone	Average	Same-Day	Cash	Processing	2
iPhone	5092653	45865	Linda Garcia	Charles4@gmail.com	2945019961	0216 Curtis Inlet	Newcastle	New South Wales	24376	Australia	...	307.289355	1843.736127	Electronics	Apple	Smartphone	Excellent	Same-Day	Cash	Delivered	5
iPhone	6118132	11415	Kathleen Eaton	Andrew32@gmail.com	7058946000	61338 Fischer Bypass Suite 473	New York	Arizona	86035	USA	...	460.028723	4140.258506	Electronics	Samsung	Smartphone	Average	Same-Day	PayPal	Delivered	2
iPhone	4915821	96525	Nicholas Brown	Victoria40@gmail.com	7353268071	96032 Payne Springs Suite 200	Boston	Georgia	30783	USA	...	151.542026	1212.336205	Electronics	Sony	Smartphone	Good	Standard	Cash	Delivered	3
iPhone	2487756	95336	Dale Drake	Donald72@gmail.com	5778370397	7900 Diaz Tunnel Apt. 148	New Orleans	Washington	99220	USA	...	44.919011	404.271098	Electronics	Sony	Smartphone	Bad	Express	Credit Card	Delivered	1
...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...
4K TV	9201039	20485	Kimberly Smith	Tyler24@gmail.com	3501601003	06159 Sarah Street Suite 100	Boston	Georgia	16713	USA	...	436.560198	2619.361190	Electronics	Samsung	Television	Average	Standard	Credit Card	Shipped	2
4K TV	8085476	47826	Derrick Barber	Steven28@gmail.com	8650339735	8504 Patty Mount	Boston	Georgia	70191	USA	...	420.197943	2521.187659	Electronics	Sony	Television	Excellent	Express	Cash	Pending	4
4K TV	5213974	66019	Gabriel Ramos	Yvonne4@gmail.com	5494389129	296 Price Greens	Hull	England	3672	UK	...	437.891935	875.783870	Electronics	Sony	Television	Bad	Standard	Debit Card	Delivered	1
4K TV	8617170	77884	Lisa Brown	Cody48@gmail.com	3426473388	9919 Huynh Rapids Suite 075	Winnipeg	Ontario	73489	Canada	...	167.268450	1505.416052	Electronics	Sony	Television	Excellent	Same-Day	PayPal	Processing	5
4K TV	8417828	50993	Tracy Munoz	Leslie90@gmail.com	8220404075	54111 Joshua Shore	Quebec City	Ontario	51527	Canada	...	191.122564	382.245127	Electronics	Samsung	Television	Excellent	Standard	Debit Card	Shipped	5
293911 rows × 29 columns
  1. Change the index of the data frame to city, state, country in the same variable

Solution
df.set_index(['City','State','Country'],inplace=True)
df

# Output

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

Solution
ndf=df.set_index('Zipcode')
ndf.sort_index(inplace=True,ascending=True)
ndf

# Output

        City	State	Country	Transaction_ID	Customer_ID	Name	Email	Phone	Address	Age	...	Total_Amount	Product_Category	Product_Brand	Product_Type	Feedback	Shipping_Method	Payment_Method	Order_Status	Ratings	products
Zipcode																					
501	San Francisco	Maine	USA	6045120	77711	Mr. David Brown	Kenneth49@gmail.com	2841244874	5506 Smith Forks Suite 869	26	...	1941.889465	Home Decor	IKEA	Decorations	Bad	Same-Day	Credit Card	Delivered	1	Curtains
501	Birmingham	England	UK	2081428	10619	David Burns	Jermaine60@gmail.com	1737652428	583 Keith Highway Apt. 605	53	...	3431.097922	Clothing	Adidas	Shoes	Good	Same-Day	Credit Card	Processing	3	High heels
502	Essen	Berlin	Germany	3525546	33693	Jacob Jackson	Amy33@gmail.com	4406902408	391 Foley Cliffs	26	...	312.909118	Electronics	Apple	Tablet	Good	Same-Day	Credit Card	Delivered	4	Acer Iconia Tab
503	Darwin	New South Wales	Australia	3765171	46329	Stephanie Dunn	Luis64@gmail.com	1265109283	458 Jackson Loaf	58	...	1002.233484	Books	Penguin Books	Fiction	Bad	Express	Debit Card	Shipped	1	Thriller
504	Düsseldorf	Berlin	Germany	7925436	99421	David Dillon	Brianna57@gmail.com	4603742358	55852 Erickson Prairie Apt. 535	22	...	20.860990	Home Decor	IKEA	Decorations	Good	Express	Cash	Delivered	3	Curtains
...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...
99948	Chicago	Connecticut	USA	5684703	34129	Amanda Allen	Ashley23@gmail.com	8450397909	8238 Lucas Mission Suite 679	34	...	1960.305154	Grocery	Pepsi	Water	Good	Same-Day	PayPal	Shipped	3	Alkaline water
99948	Austin	Alaska	USA	8509706	86844	Andrea Jones	Angel14@gmail.com	1491002908	39250 Martinez Canyon Apt. 705	26	...	710.609379	Electronics	Whirepool	Fridge	Good	Standard	Debit Card	Delivered	3	Side-by-side refrigerator
99949	Oklahoma City	Alaska	USA	3652401	90991	Rachel Ramos	Nicole26@gmail.com	6084399608	886 Matthew Highway	41	...	95.049001	Grocery	Coca-Cola	Water	Average	Express	Cash	Pending	2	Artesian water
99949	Mesa	Alaska	USA	7100236	15232	Nancy Welch	Christopher35@gmail.com	2815554860	7703 Gina Shore Suite 732	44	...	3885.747891	Home Decor	Home Depot	Tools	Good	Standard	Credit Card	Processing	3	Screwdriver set
99949	Boston	Georgia	USA	3841207	27689	Jeremiah Ryan	Matthew39@gmail.com	8669015748	2822 Richard Street Apt. 374	23	...	1126.469740	Books	HarperCollins	Thriller	Excellent	Standard	Credit Card	Processing	5	Detective
293911 rows × 29 columns
  1. Reset the index of the above data frame in the same variable.

Solution
ndf.reset_index(inplace=True)
ndf

# Output

Zipcode	City	State	Country	Transaction_ID	Customer_ID	Name	Email	Phone	Address	...	Total_Amount	Product_Category	Product_Brand	Product_Type	Feedback	Shipping_Method	Payment_Method	Order_Status	Ratings	products
0	501	San Francisco	Maine	USA	6045120	77711	Mr. David Brown	Kenneth49@gmail.com	2841244874	5506 Smith Forks Suite 869	...	1941.889465	Home Decor	IKEA	Decorations	Bad	Same-Day	Credit Card	Delivered	1	Curtains
1	501	Birmingham	England	UK	2081428	10619	David Burns	Jermaine60@gmail.com	1737652428	583 Keith Highway Apt. 605	...	3431.097922	Clothing	Adidas	Shoes	Good	Same-Day	Credit Card	Processing	3	High heels
2	502	Essen	Berlin	Germany	3525546	33693	Jacob Jackson	Amy33@gmail.com	4406902408	391 Foley Cliffs	...	312.909118	Electronics	Apple	Tablet	Good	Same-Day	Credit Card	Delivered	4	Acer Iconia Tab
3	503	Darwin	New South Wales	Australia	3765171	46329	Stephanie Dunn	Luis64@gmail.com	1265109283	458 Jackson Loaf	...	1002.233484	Books	Penguin Books	Fiction	Bad	Express	Debit Card	Shipped	1	Thriller
4	504	Düsseldorf	Berlin	Germany	7925436	99421	David Dillon	Brianna57@gmail.com	4603742358	55852 Erickson Prairie Apt. 535	...	20.860990	Home Decor	IKEA	Decorations	Good	Express	Cash	Delivered	3	Curtains
...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...	...
293906	99948	Chicago	Connecticut	USA	5684703	34129	Amanda Allen	Ashley23@gmail.com	8450397909	8238 Lucas Mission Suite 679	...	1960.305154	Grocery	Pepsi	Water	Good	Same-Day	PayPal	Shipped	3	Alkaline water
293907	99948	Austin	Alaska	USA	8509706	86844	Andrea Jones	Angel14@gmail.com	1491002908	39250 Martinez Canyon Apt. 705	...	710.609379	Electronics	Whirepool	Fridge	Good	Standard	Debit Card	Delivered	3	Side-by-side refrigerator
293908	99949	Oklahoma City	Alaska	USA	3652401	90991	Rachel Ramos	Nicole26@gmail.com	6084399608	886 Matthew Highway	...	95.049001	Grocery	Coca-Cola	Water	Average	Express	Cash	Pending	2	Artesian water
293909	99949	Mesa	Alaska	USA	7100236	15232	Nancy Welch	Christopher35@gmail.com	2815554860	7703 Gina Shore Suite 732	...	3885.747891	Home Decor	Home Depot	Tools	Good	Standard	Credit Card	Processing	3	Screwdriver set
293910	99949	Boston	Georgia	USA	3841207	27689	Jeremiah Ryan	Matthew39@gmail.com	8669015748	2822 Richard Street Apt. 374	...	1126.469740	Books	HarperCollins	Thriller	Excellent	Standard	Credit Card	Processing	5	Detective
293911 rows × 30 columns

75MB
retail_data.csv