I would like to put some standard tasks for a panda dataframe like initialize with data and process this data into a class. I am currently performing the following sample steps:
import pandas as pd
import urllib.request
def __get_data():
URL = r'https://en.wikipedia.org/wiki/List_of_sovereign_states_' \
r'and_dependent_territories_by_continent_(data_file)#Data_file'
HTML_STRING = urllib.request.urlopen(URL)
return pd.read_html(HTML_STRING)[2]
def __prepare_data(df):
df.iloc[:,-1] = df.iloc[:,-1].str.upper()
return df
MyDataFrame = pd.DataFrame()
MyDataFrame = __get_data()
MyDataFrame = __prepare_data(MyDataFrame)
I'd like something like that:
class MyDataFrame(pd.DataFrame):
def __init__(self, *args, **kwargs):
super(MyDataFrame, self).__init__(*args, **kwargs)
self = self.__get_data()
self.__prepare_data()
def __get_data(self):
URL = r'https://en.wikipedia.org/wiki/List_of_sovereign_states_' \
r'and_dependent_territories_by_continent_(data_file)#Data_file'
HTML_STRING = urllib.request.urlopen(URL)
return pd.read_html(HTML_STRING)[2]
def __prepare_data(self):
self.iloc[:, -1] = self.iloc[:, -1].str.upper()
Unfortunately I do not understand the Pandas documentation in this context.