import pandas as pd
amazon_2 = pd.read_csv(r"C:\Users\User\Desktop\archive\amazon.csv",index_col=0)
amazon_2.head()
Category | Product Link | No of Sellers | Rank | Rating | Reviews Count | Price | |
---|---|---|---|---|---|---|---|
ASIN | |||||||
B079QHML21 | Electronics | https://www.amazon.com/gp/offer-listing/B079QH... | 1 Sellers | #1 | 4.7 | 640,721 | $39.99 |
B07FZ8S74R | Electronics | https://www.amazon.com/gp/offer-listing/B07FZ8... | 1 Sellers | #2 | 4.7 | 854,114 | $34.99 |
B07XJ8C8F5 | Electronics | https://www.amazon.com/gp/offer-listing/B07XJ8... | 1 Sellers | #3 | 4.7 | 267,821 | $44.99 |
B07WVFCVJN | Electronics | https://www.amazon.com/gp/offer-listing/B07WVF... | 27 Sellers | #4 | 4.8 | 114,267 | $28.48 |
B08YT2N5SX | Electronics | https://www.amazon.com/gp/offer-listing/B08YT2... | 1 Sellers | #5 | 4.7 | 267,821 | $49.99 |
amazon_2.head()
Category | Product Link | No of Sellers | Rank | Rating | Reviews Count | Price | |
---|---|---|---|---|---|---|---|
ASIN | |||||||
B079QHML21 | Electronics | https://www.amazon.com/gp/offer-listing/B079QH... | 1 Sellers | #1 | 4.7 | 640,721 | $39.99 |
B07FZ8S74R | Electronics | https://www.amazon.com/gp/offer-listing/B07FZ8... | 1 Sellers | #2 | 4.7 | 854,114 | $34.99 |
B07XJ8C8F5 | Electronics | https://www.amazon.com/gp/offer-listing/B07XJ8... | 1 Sellers | #3 | 4.7 | 267,821 | $44.99 |
B07WVFCVJN | Electronics | https://www.amazon.com/gp/offer-listing/B07WVF... | 27 Sellers | #4 | 4.8 | 114,267 | $28.48 |
B08YT2N5SX | Electronics | https://www.amazon.com/gp/offer-listing/B08YT2... | 1 Sellers | #5 | 4.7 | 267,821 | $49.99 |
productLink_series =amazon_2['Product Link']
productLink_series
ASIN B079QHML21 https://www.amazon.com/gp/offer-listing/B079QH... B07FZ8S74R https://www.amazon.com/gp/offer-listing/B07FZ8... B07XJ8C8F5 https://www.amazon.com/gp/offer-listing/B07XJ8... B07WVFCVJN https://www.amazon.com/gp/offer-listing/B07WVF... B08YT2N5SX https://www.amazon.com/gp/offer-listing/B08YT2... ... B007DW6F34 https://www.amazon.com/gp/offer-listing/B007DW... B01N16VX79 https://www.amazon.com/gp/offer-listing/B01N16... B09197N995 https://www.amazon.com/gp/offer-listing/B09197... B015CCR1FW https://www.amazon.com/gp/offer-listing/B015CC... B07TS96J7Q https://www.amazon.com/gp/offer-listing/B07TS9... Name: Product Link, Length: 707, dtype: object
productLink_DataFrame = amazon_2[['Product Link']]
productLink_DataFrame
Product Link | |
---|---|
ASIN | |
B079QHML21 | https://www.amazon.com/gp/offer-listing/B079QH... |
B07FZ8S74R | https://www.amazon.com/gp/offer-listing/B07FZ8... |
B07XJ8C8F5 | https://www.amazon.com/gp/offer-listing/B07XJ8... |
B07WVFCVJN | https://www.amazon.com/gp/offer-listing/B07WVF... |
B08YT2N5SX | https://www.amazon.com/gp/offer-listing/B08YT2... |
... | ... |
B007DW6F34 | https://www.amazon.com/gp/offer-listing/B007DW... |
B01N16VX79 | https://www.amazon.com/gp/offer-listing/B01N16... |
B09197N995 | https://www.amazon.com/gp/offer-listing/B09197... |
B015CCR1FW | https://www.amazon.com/gp/offer-listing/B015CC... |
B07TS96J7Q | https://www.amazon.com/gp/offer-listing/B07TS9... |
707 rows × 1 columns
0: 3 means frpm 0 to 3 row
first_3_row = amazon_2[0:3]
first_3_row
Category | Product Link | No of Sellers | Rank | Rating | Reviews Count | Price | |
---|---|---|---|---|---|---|---|
ASIN | |||||||
B079QHML21 | Electronics | https://www.amazon.com/gp/offer-listing/B079QH... | 1 Sellers | #1 | 4.7 | 640,721 | $39.99 |
B07FZ8S74R | Electronics | https://www.amazon.com/gp/offer-listing/B07FZ8... | 1 Sellers | #2 | 4.7 | 854,114 | $34.99 |
B07XJ8C8F5 | Electronics | https://www.amazon.com/gp/offer-listing/B07XJ8... | 1 Sellers | #3 | 4.7 | 267,821 | $44.99 |
select_3_row_and_1_column = amazon_2[0:3][['Rank']]
select_3_row_and_1_column
Rank | |
---|---|
ASIN | |
B079QHML21 | #1 |
B07FZ8S74R | #2 |
B07XJ8C8F5 | #3 |
select_2_row_and_2_column = amazon_2[0:2][['Rank','Rating']]
select_2_row_and_2_column
Rank | Rating | |
---|---|---|
ASIN | ||
B079QHML21 | #1 | 4.7 |
B07FZ8S74R | #2 | 4.7 |
spRow_spCol_loc=amazon_2.loc[["B07FZ8S74R"],["Rank"]]
spRow_spCol_loc
Rank | |
---|---|
ASIN | |
B07FZ8S74R | #2 |
twoRow_twoCol_loc=amazon_2.loc[["B07FZ8S74R","B09197N995"],["Rank","Rating"]]
twoRow_twoCol_loc
Rank | Rating | |
---|---|---|
ASIN | ||
B07FZ8S74R | #2 | 4.7 |
B09197N995 | #97 | 4.8 |
spRow_spCol_iloc=amazon_2.iloc[[1],[4]]
spRow_spCol_iloc
Rating | |
---|---|
ASIN | |
B07FZ8S74R | 4.7 |
twoRow_twoCol_iloc=amazon_2.iloc[[1,706],[4,5]]
twoRow_twoCol_iloc
Rating | Reviews Count | |
---|---|---|
ASIN | ||
B07FZ8S74R | 4.7 | 854,114 |
B07TS96J7Q | 4.7 | 12,902 |
movie ={ "Avenger":{'Type':"Scifi", 'Rating':"Public"},
"Fast and Furious":{'Type':"Action",'Rating':"16 Above"},
"Carrie":{'Type':"Horror",'Rating':"16 Above"},
"Jumanji":{'Type':"Comedy",'Rating':"Public"},
"Ice Age":{'Type':"Cartoon",'Rating':"Public"},
"Resident Evil":{'Type':"Gore",'Rating':"16 Above"},
"Basic Instinct":{'Type':"Adult",'Rating':"18 Above"}
}
movie_frame =pd.DataFrame(movie)
movie_frame
Avenger | Fast and Furious | Carrie | Jumanji | Ice Age | Resident Evil | Basic Instinct | |
---|---|---|---|---|---|---|---|
Type | Scifi | Action | Horror | Comedy | Cartoon | Gore | Adult |
Rating | Public | 16 Above | 16 Above | Public | Public | 16 Above | 18 Above |
mf_1row_2col_loc =movie_frame.loc[["Type"],["Carrie","Jumanji"]]
mf_1row_2col_loc
Carrie | Jumanji | |
---|---|---|
Type | Horror | Comedy |
movie2= [ ('Avenger', 'Scifi', 'Public'),
('Fast and Furious', 'Action', '16 Above'),
('Carrie', 'Horror', '16 Above'),
('Jumanji', 'Comedy', 'Public'),
('Ice Age', 'Cartoon', 'Public'),
('Resident Evil', 'Gore', '16 Above'),
('Basic Instinct', 'Adult', '18 Above')
]
Since pandas DataFrames and Series always have an index, you can’t actually drop the index, but you can reset it by using the following bit of code:
movie_frame_2 = pd.DataFrame(movie2, columns =['Name', 'Type', 'Rating'])
movie_frame_2.reset_index(drop=True, inplace=True)
movie_frame_2
Name | Type | Rating | |
---|---|---|---|
0 | Avenger | Scifi | Public |
1 | Fast and Furious | Action | 16 Above |
2 | Carrie | Horror | 16 Above |
3 | Jumanji | Comedy | Public |
4 | Ice Age | Cartoon | Public |
5 | Resident Evil | Gore | 16 Above |
6 | Basic Instinct | Adult | 18 Above |
movie_frame_test = pd.DataFrame(movie2, columns =['Name', 'Type', 'Rating'],index=['Movie_1','Movie_2','Movie_3','Movie_4'
,'Movie_5','Movie_6','Movie_7'])
movie_frame_test
Name | Type | Rating | |
---|---|---|---|
Movie_1 | Avenger | Scifi | Public |
Movie_2 | Fast and Furious | Action | 16 Above |
Movie_3 | Carrie | Horror | 16 Above |
Movie_4 | Jumanji | Comedy | Public |
Movie_5 | Ice Age | Cartoon | Public |
Movie_6 | Resident Evil | Gore | 16 Above |
Movie_7 | Basic Instinct | Adult | 18 Above |
movie_frame_2.style.hide_index()
Name | Type | Rating |
---|---|---|
Avenger | Scifi | Public |
Fast and Furious | Action | 16 Above |
Carrie | Horror | 16 Above |
Jumanji | Comedy | Public |
Ice Age | Cartoon | Public |
Resident Evil | Gore | 16 Above |
Basic Instinct | Adult | 18 Above |
movie_frame_2
Name | Type | Rating | |
---|---|---|---|
0 | Avenger | Scifi | Public |
1 | Fast and Furious | Action | 16 Above |
2 | Carrie | Horror | 16 Above |
3 | Jumanji | Comedy | Public |
4 | Ice Age | Cartoon | Public |
5 | Resident Evil | Gore | 16 Above |
6 | Basic Instinct | Adult | 18 Above |
mf_1row_2col_iloc=movie_frame_2.iloc[[1],[1,2]]
mf_1row_2col_iloc
Type | Rating | |
---|---|---|
1 | Action | 16 Above |
name = ['Avenger','Fast and Furious','Carrie','Jumanji','Ice Age','Resident Evil','Basic Instinct']
types =['scifi','Action','Horor','Comedy','Cartoon','Gore','Adult']
rating=['Public','16 Above','16 Above','Public','Public','16 Above','18 Above']
movie3 ={'Name':name,'Type':types,'Rating':rating}
movie_frame_3 =pd.DataFrame(movie3)
movie_frame_3
Name | Type | Rating | |
---|---|---|---|
0 | Avenger | scifi | Public |
1 | Fast and Furious | Action | 16 Above |
2 | Carrie | Horor | 16 Above |
3 | Jumanji | Comedy | Public |
4 | Ice Age | Cartoon | Public |
5 | Resident Evil | Gore | 16 Above |
6 | Basic Instinct | Adult | 18 Above |