49 lines
1.5 KiB
Python
49 lines
1.5 KiB
Python
from typing import Any, Dict
|
|
import pandas as pd
|
|
import datetime
|
|
|
|
|
|
class PandasIatDatetime:
|
|
"""
|
|
Selects a cell from a pandas DataFrame and output as a Python datetime.datetime data.
|
|
|
|
category: Data subset selection
|
|
"""
|
|
|
|
@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})
|
|
}
|
|
}
|
|
|
|
RETURN_TYPES: tuple = ("PYDATETIME",)
|
|
FUNCTION: str = "f"
|
|
CATEGORY: str = "Data Analysis"
|
|
|
|
def f(self, dataframe: pd.DataFrame,
|
|
row_integer_position: int,
|
|
column_integer_position: int) -> tuple:
|
|
"""
|
|
Selects specific cell from 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.
|
|
|
|
Returns:
|
|
tuple: A tuple containing the value of the cell.
|
|
"""
|
|
value = dataframe.iat[row_integer_position, column_integer_position]
|
|
return (value.to_pydatetime(),)
|