AutoSkill Custom Python DataFrame Class Implementation
Implement a custom DataFrame class in Python with specific methods (__init__, set_index, __setitem__, __getitem__, loc, iteritems, iterrows, as_type, drop, mean, __repr__) that handles list-based data inputs and outputs CSV-formatted strings with row indices.
install
source · Clone the upstream repo
git clone https://github.com/ECNU-ICALK/AutoSkill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt4_8_GLM4.7/custom-python-dataframe-class-implementation" ~/.claude/skills/ecnu-icalk-autoskill-custom-python-dataframe-class-implementation && rm -rf "$T"
manifest:
SkillBank/ConvSkill/english_gpt4_8_GLM4.7/custom-python-dataframe-class-implementation/SKILL.mdsource content
Custom Python DataFrame Class Implementation
Implement a custom DataFrame class in Python with specific methods (init, set_index, setitem, getitem, loc, iteritems, iterrows, as_type, drop, mean, repr) that handles list-based data inputs and outputs CSV-formatted strings with row indices.
Prompt
Role & Objective
You are a Python developer tasked with implementing a custom DataFrame class. The class must support specific methods and handle data input/output in a particular format.
Operational Rules & Constraints
- Class Structure: Implement a class named
.DataFrame - Attributes:
: A dictionary to map text to row index.self.index
: A dictionary where keys are column names and values areself.data
objects.ListV2
: A list or tuple of column names.self.columns
- Methods:
: Initialize the DataFrame. Handle__init__(self, data, columns)
as a list of lists (rows) or a dictionary. Ifdata
is a list, populatedata
by iterating through rows and zipping withself.data
.columns
: Set the index using a column name.set_index(self, index)
: Set or add a column.__setitem__(self, col_name, values)
: Retrieve data. If__getitem__(self, col_name)
is a string, return the list of values for that column. Ifcol_name
is a list of strings, return a CSV-formatted string containing the index and those columns.col_name
: Retrieve a row by index name.loc(self, row_name)
: Iterate over columns.iteritems(self)
: Iterate over rows.iterrows(self)
: Convert data types.as_type(self, dtype, col_name)
: Remove a column.drop(self, col_name)
: Calculate mean for columns.mean(self)
: Return a string representation of the DataFrame.__repr__(self)
- Output Format:
and multi-column__repr__
must return a CSV-formatted string.__getitem__- The header row must start with an empty string (e.g.,
).,Col1,Col2 - Subsequent rows must start with the row index (e.g.,
).0,val1,val2 - Ensure proper handling of tuple/list concatenation when building the table structure.
- Helper Class: Use a
class to wrap lists, ensuring it has anListV2
method or behaves like a list for data population.append
Anti-Patterns
- Do not use pandas or external libraries unless specified.
- Do not return the DataFrame object itself when
receives a list of columns; return the formatted string.__getitem__ - Do not assume
is always a list; handle tuples as well.self.columns
Triggers
- implement dataframe class
- custom dataframe python
- dataframe init getitem
- fix dataframe error
- dataframe csv output