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
9 changes: 6 additions & 3 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 Down Expand Up @@ -106,9 +109,9 @@ def apply_function(df: pd.DataFrame, column: str, func: Callable) -> List[Any]:

def fillna(df: pd.DataFrame, column: str, value: Any) -> pd.DataFrame:
result = df.copy()
for i in range(len(df)):
if pd.isna(df.iloc[i][column]):
result.iloc[i, df.columns.get_loc(column)] = value
# Replace NA values in the specified column using efficient vectorized operation
mask = result[column].isna()
result.loc[mask, column] = value
return result


Expand Down