Files

53 lines
1.7 KiB
Python

from typing import Any, Dict
import pandas as pd
import datetime
class PandasIatSetDatetime:
"""
Sets a Python datetime.datetime data in a cell in a pandas DataFrame.
This modifies the input DataFrame in place.
category: Transformation
"""
@classmethod
def INPUT_TYPES(cls) -> Dict[str, Any]:
"""
Defines the input types for the `cell` function.
Returns:
Dict[str, Any]: A dictionary specifying required input types.
"""
return {
"required": {
"dataframe": ("DATAFRAME", {}),
"row_integer_position": ("INT", {"default": 0, "min": 0, "max": 2**31}),
"column_integer_position": ("INT", {"default": 0, "min": 0, "max": 2**31}),
"data": ("PYDATETIME", {})
}
}
RETURN_TYPES: tuple = ("DATAFRAME",)
FUNCTION: str = "f"
CATEGORY: str = "Data Analysis"
def f(self, dataframe: pd.DataFrame,
row_integer_position: int,
column_integer_position: int,
data: datetime.datetime) -> tuple:
"""
Sets a Python datetime.datetime data in a cell in a pandas DataFrame.
Args:
dataframe (DataFrame): The DataFrame.
row_integer_position (int): The row integer position for the cell.
column_integer_position (int): The row integer position for the cell.
data: datetime.datetime (datetime.datetime): The value to set in the cell.
Returns:
tuple: A tuple containing the updated DataFrame.
"""
dataframe.iat[row_integer_position, column_integer_position] = data
return (dataframe,)