This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Student: # student is the class | |
def __init__(self, fname, rollno, age): | |
self.fname = fname # object attributes | |
self.rollno = rollno | |
self.age = age | |
std1 = Student('Raman', 42, 14) # object of the class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Student: | |
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data['pickup_year'] = data['pickup_datetime'].dt.year | |
data['pickup_dayofyear'] = data['pickup_datetime'].dt.day | |
data['pickup_monthofyear'] = data['pickup_datetime'].dt.month | |
data['pickup_hourofday'] = data['pickup_datetime'].dt.hour | |
data['pickup_dayofweek'] = data['pickup_datetime'].dt.dayofweek | |
data['pickup_weekofyear'] = data['pickup_datetime'].dt.weekofyear |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data['Item_Outlet_Sales_Mean'] = data.groupby(['Item_Identifier', 'Item_Type'])['Item_Outlet_Sales']\ | |
.transform(lambda x: x.mean()) | |
data[['Item_Identifier','Item_Type','Item_Outlet_Sales','Item_Outlet_Sales_Mean']].tail() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Frequency encoding using value_counts function | |
Item_Type_freq = data['Item_Type'].value_counts(normalize=True) | |
# Mapping the encoded values with original data | |
data['Item_Type_freq'] = data['Item_Type'].apply(lambda x : Item_Type_freq[x]) | |
print('The sum of Item_Type_freq variable:', sum(Item_Type_freq)) | |
data[['Item_Type', 'Item_Type_freq']].head(6) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data['Item_Code'] = data['Item_Identifier'].apply(lambda x: x[0:2]) | |
data[['Item_Identifier', 'Item_Code']].head() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Count of each category | |
pd.DataFrame(data['Item_MRP_Bin_cut'].value_counts()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define bins | |
bins = [0, 70, 140, 210, 280] | |
#name of groups | |
groups = ['Low', 'Med', 'High', 'Exp'] | |
data['Item_MRP_Bin_cut'] = pd.cut(data['Item_MRP'], bins=bins, labels=groups) | |
data[['Item_MRP', 'Item_MRP_Bin_cut']].head() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Count of each category | |
pd.DataFrame(data['Item_MRP_Bin_qcut'].value_counts()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#name of groups | |
groups = ['Low', 'Med', 'High', 'Exp'] | |
data['Item_MRP_Bin_qcut'] = pd.qcut(data['Item_MRP'], q=4, labels=groups) | |
data[['Item_MRP', 'Item_MRP_Bin_qcut']].head() |
NewerOlder