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
import pandas as pd | |
import random | |
class DemoClass: | |
#Class members | |
df = pd.DataFrame() | |
a = [] | |
#Initialization | |
def __init__(self): | |
self.df = pd.DataFrame({'A':[1,2,3,4],'B':[5,6,7,8]}) | |
for i in range(1,56): | |
self.a.append(i) | |
print('Initialized values') | |
print(self.df) | |
print(self.a) | |
#Custom methods modify | |
def modify(self): | |
self.df = self.df.drop('A',1) | |
print('Modified df') | |
print(self.df) | |
#Custom methods reinitialize | |
def reinitialize(self): | |
print('Reinitialized') | |
self.df = pd.DataFrame({1:[1,2,3,4],2:[1,2,3,4],10:[1,2,3,4]}) | |
self.df = self.df.drop(1,1) | |
#Custom methods displaydata | |
def displaydata(self): | |
print('In Display Data') | |
print(random.sample(self.a,15)) | |
print(self.df) | |
#Object Creation | |
x = DemoClass() | |
#Methods Invocation | |
x.displaydata() | |
x.modify() | |
x.displaydata() | |
x.reinitialize() | |
x.displaydata() |