3. Series - Basic Operations

  1. Load the data and access name series.

Solution
import pandas as pd

df=pd.read_csv('retail_data.csv')
print(df['Name'])

#  Output

0         Michelle Harrington
1                 Kelsey Hill
2                Scott Jensen
3               Joseph Miller
4               Debra Coleman
                 ...         
293906           Meagan Ellis
293907            Mathew Beck
293908             Daniel Lee
293909         Patrick Wilson
293910         Dustin Merritt
Name: Name, Length: 293911, dtype: object
  1. Display address, zipcode, city, state and country column.

Solution
df[['Address','Zipcode','City','State','Country']]

# Output

	Address	Zipcode	City	State	Country
0	3959 Amanda Burgs	77985	Dortmund	Berlin	Germany
1	82072 Dawn Centers	99071	Nottingham	England	UK
2	4133 Young Canyon	75929	Geelong	New South Wales	Australia
3	8148 Thomas Creek Suite 100	88420	Edmonton	Ontario	Canada
4	5813 Lori Ports Suite 269	48704	Bristol	England	UK
...	...	...	...	...	...
293906	389 Todd Path Apt. 159	4567	Townsville	New South Wales	Australia
293907	52809 Mark Forges	16852	Hanover	Berlin	Germany
293908	407 Aaron Crossing Suite 495	88038	Brighton	England	UK
293909	3204 Baird Port	67608	Halifax	Ontario	Canada
293910	143 Amanda Crescent	25242	Tucson	West Virginia	USA
293911 rows × 5 columns
  1. Display all the columns that are related to products.

Solution
df[['Product_Category','Product_Brand','Product_Type','products']]

# Output

Product_Category	Product_Brand	Product_Type	products
0	Clothing	Nike	Shorts	Cycling shorts
1	Electronics	Samsung	Tablet	Lenovo Tab
2	Books	Penguin Books	Children's	Sports equipment
3	Home Decor	Home Depot	Tools	Utility knife
4	Grocery	Nestle	Chocolate	Chocolate cookies
...	...	...	...	...
293906	Books	Penguin Books	Fiction	Historical fiction
293907	Electronics	Apple	Laptop	LG Gram
293908	Clothing	Adidas	Jacket	Parka
293909	Home Decor	IKEA	Furniture	TV stand
293910	Home Decor	Home Depot	Decorations	Clocks
293911 rows × 4 columns
  1. Create a new column with 100 stored in it as value.

Solution
  1. Create a new column that holds serial number 1 to last row.

Solution
  1. Create a new column with random values between 1,1000.

Solution
  1. Create a column for total sales.

Solution
  1. Find out the birth year of the customers.

Solution
  1. Update the address column and add the city name along with the address.

Solution
  1. Load the data and display all the invoice numbers.

Solution
  1. Display the details and address with zipcode of all the stores.

Solution
  1. Create a new column Beverage Type with values 'LIQUOR'. Store columns like category, category name, item description, and beverage type in a variable and display all values.

Solution
  1. Create a new column Liquor Type with random values among (whiskey, rum, vodka). Store columns like category, category name, item description, and beverage type in a variable and display all values.

Solution
  1. Calculate margin earned by retailers on each bottle.

Solution
  1. Update the values of the column Volume Sold (Liters) into ml.

Solution

Last updated