surveyweathertool.src.dashboard.utils¶
Module Contents¶
Functions¶
|
Reads and returns the STC, UNICEF, DSA, and NOAA logos from the provided path. |
|
Filters the given DataFrame based on the provided year, month, or season. |
|
Filters the given survey DataFrame based on the provided wave. |
Checks if a dataframe has columns named "lat" and "long". |
|
|
Lower-cases all column names and converts date column to datetime. |
|
Lower-cases all column names, converts date column to datetime & gets year/month as features. |
|
Load data from Google Drive into a DataFrame |
|
Read data from various file formats and return a DataFrame. |
- surveyweathertool.src.dashboard.utils.read_logos(logos_path)¶
Reads and returns the STC, UNICEF, DSA, and NOAA logos from the provided path.
Parameters:¶
- logos_pathstr
The path to the directory containing the logo images.
Returns:¶
- tuple of PIL.Image.Image
The STC, UNICEF, and DSA logos as PIL Image objects.
- surveyweathertool.src.dashboard.utils.filter_weather(weather_df: pandas.DataFrame, year: int, month: int = None, season: str = None)¶
Filters the given DataFrame based on the provided year, month, or season.
Parameters:¶
- weather_dfpandas.DataFrame
The DataFrame to filter.
- yearint
The year to filter on. Can be a specific year as a string or “All Years” to include all years.
- monthint, optional
The month to filter on. Can be a specific month as an integer (1-12) or None.
- seasonstr, optional
The season to filter on. Can be a specific season as a string or None.
Returns:¶
- pandas.DataFrame
The filtered DataFrame.
- surveyweathertool.src.dashboard.utils.filter_survey(survey_df: pandas.DataFrame, wave: int = 1, target_epsg: int = 4326)¶
Filters the given survey DataFrame based on the provided wave.
Parameters:¶
- survey_dfpandas.DataFrame
The DataFrame to filter.
- waveint, Optional
The wave to filter on. Can be a specific wave. Defaults to 1.
Returns:¶
- pandas.DataFrame
The filtered DataFrame.
- surveyweathertool.src.dashboard.utils.check_if_df_has_lat_long(df: pandas.DataFrame)¶
Checks if a dataframe has columns named “lat” and “long”.
Keyword arguments: df – the dataframe to check
- surveyweathertool.src.dashboard.utils.preprocess_data_input(df: pandas.DataFrame) pandas.DataFrame¶
Lower-cases all column names and converts date column to datetime.
Keyword arguments: df – the dataframe to check
- surveyweathertool.src.dashboard.utils.preprocess_weather_data(df: pandas.DataFrame) pandas.DataFrame¶
Lower-cases all column names, converts date column to datetime & gets year/month as features.
Keyword arguments: df – the dataframe to preprocess
- surveyweathertool.src.dashboard.utils.load_data_from_google_drive(file_to_load: str)¶
Load data from Google Drive into a DataFrame :param file_to_load: The ID of the file to load from Google Drive :return: A DataFrame containing the data from the file
- surveyweathertool.src.dashboard.utils.dataframe_reader(file_path: pathlib.Path, use_columns: List[str] | None = None, reset_index=False, *kwargs) pandas.DataFrame¶
Read data from various file formats and return a DataFrame.
- Parameters:
file_path (Path): The path to the input file. use_columns (Optional[List[str]]): A list of column names to include in the DataFrame.
If None, all columns will be included. Default is None.
reset_index (bool): Flag if want to reset index from original file. *kwargs (Optional[List]): Any keyword arguments to be passed to pandas reader function
- Returns:
pd.DataFrame: A DataFrame containing the data from the input file.
- Raises:
ValueError: If the file type is not supported.
- Note:
Supported file formats: ‘.csv’, ‘.sav’, ‘.dta’, ‘.pickle’.