I’m trying to make a custom class CsvFrame
that is a dataframe made either with pandas or polars.
For that I made the code below :
class CsvFrame:
def __init__(self, engine, *args, **kwargs):
if engine == 'polars':
import polars as pl
pl.DataFrame.__init__(pl.read_csv(*args, **kwargs))
if engine == 'pandas':
import pandas as pd
pd.DataFrame.__init__(pd.read_csv(*args, **kwargs))
Now when I instantiante an object, there is two problems :
- there is not html represention of the dataframe in my vscode-jupyter
- none of the methods or the attributes of a dataframe are available
import io
input_text = '''
col1,col2
A,1
B,2
'''
cfr = CsvFrame('polars', io.StringIO(input_text))
# problem 1
cfr # <__main__.CsvFrame at 0x1fd721f32c0>
# problem 2
cfr.melt()
AttributeError: 'CsvFrame' object has no attribute 'melt'
Can you guys help me fix that ?