Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/numpy_pandas/dataframe_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,17 @@ def pivot_table(

def agg_func(values):
return sum(values) / len(values)

elif aggfunc == "sum":

def agg_func(values):
return sum(values)

elif aggfunc == "count":

def agg_func(values):
return len(values)

else:
raise ValueError(f"Unsupported aggregation function: {aggfunc}")
grouped_data = {}
Expand All @@ -97,11 +100,8 @@ def agg_func(values):


def apply_function(df: pd.DataFrame, column: str, func: Callable) -> List[Any]:
result = []
for i in range(len(df)):
value = df.iloc[i][column]
result.append(func(value))
return result
# Use vectorized map for better performance
return list(df[column].map(func))


def fillna(df: pd.DataFrame, column: str, value: Any) -> pd.DataFrame:
Expand Down