I am trying to create a class derived from pandas DataFrame. The class shall have each an attribute of type string, DataFrame and list. There is no problem with the string attribute, but DataFrame and list each cause a warning. Despite the warnings, the code seems to behave correctly.
Can anyone help me to fix my code? Or suppress the warnings?
Code:
import pandas as pd
class MyClass(pd.DataFrame):
def __init__(self, arg_string, arg_dataframe, *arg_params):
pd.DataFrame.__init__(self)
self._string = arg_string
self._dataframe = arg_dataframe
self._params = arg_params
if __name__=='__main__':
df = pd.DataFrame()
c1 = MyClass("test", df, 1, 2, 3)
print(c1._string)
print(c1._dataframe)
print(c1._params)
Warning message:
so_example.py:7: UserWarning: Pandas doesn't allow columns to be created via a new attribu
te name - see https://pandas.pydata.org/pandas-docs/stable/indexing.html#attribute-access
self._dataframe = arg_dataframe
so_example.py:8: UserWarning: Pandas doesn't allow columns to be created via a new attribu
te name - see https://pandas.pydata.org/pandas-docs/stable/indexing.html#attribute-access
self._params = arg_params
Stdout:
test
Empty DataFrame
Columns: []
Index: []
(1, 2, 3)