unithon

unithon.adapt_frequency(df_, new_frequency=60, start_date=None, end_date=None, time_column_name='date_time')

This function changes the refresh frequency of a dataframe.

Parameters:
  • df (pandas.DataFrame) – dataframes of all houses.
  • new_frequency (int, optional) – refresh frequency in minutes of the output.
  • start_date (datetime, optional) – left extreme of the selected time interval.
  • end_date (datetime, optional) – right extreme of the selected time interval.
  • time_column_name (str, optional) – name of the column containing the time information.
Returns:

The function returns a pandas dataframe with the selected refresh frequency.

Return type:

pandas.DataFrame

unithon.df_house_sensor(df_, house_number, sensor)

This function extracts the information of a specific sensor in a certain house from a dataframe.

Parameters:
  • df (pandas.DataFrame) – dataframe containing all data.
  • house_number (int) – number of the house which data is getting extracted.
  • sensor (int or str) – name/number of the sensor which data is getting extracted.
Returns:

The function returns a dataframe containing the data of a specific sensor in a certain house.

Return type:

pandas.DataFrame

unithon.fix_date_format(df_, date_format='%d %m %Y %H:%M', date_column_name='hour')

This function converts the data column into ‘datetime’ format.

Parameters:
  • df (pandas.DataFrame) – Input dataset.
  • date_format (str, optional) – format in which the dates are embedded.
  • date_column_name (str, optional) – name of the column containing the dates.
Returns:

The function returns a dataframe with the date column in datetime format.

Return type:

pandas.DataFrame

unithon.fix_empty_weeks(df_, column)

This function fulfills the empty gaps found in a dataset.

Parameters:
  • df (pandas.DataFrame) – Input dataset.
  • column (int) – column’s position (as number in the dataframe).
Returns:

The function returns the fixed dataframe.

Return type:

bool

unithon.fix_month_format(element)

This function converts the abbreviation of a Spanish month into its corresponding month number.

Parameters:element (str) – name of the month in Spanish. Abbreviation of the first 3 letters.
Returns:The function returns the corresponding number as string.
Return type:str
unithon.get_df_house(df_, house_number, frequency=60, time_column_name='date_time')

This function extracts the dataframe of a specific house from a general dataframe.

Parameters:
  • df (pandas.DataFrame) – dataframes of all houses.
  • house_number (str) – number of the selected house.
  • frequency (int, optional) – refresh frequency in minutes of the output.
  • time_column_name (str, optional) – name of the column containing the time information.
Returns:

The function returns a pandas dataframe with all the information of the selected house.

Return type:

pandas.DataFrame

unithon.load_data(original_path='./concatenado', date_format='%d %m %Y %H:%M', sort_values=True, date_column_name='hour')

This function loads information from several files and outputs a single dataset containing all the information.

Parameters:
  • original_path (str, optional) – path where all the files are located.
  • date_format (str, optional) – format in which the dates are embedded.
  • sort_values (bool, optional) – sort the values by data or preserve the original order.
  • date_column_name (str, optional) – name of the column containing the dates.
Returns:

The function returns a pandas.DataFrame containing all the loaded data.

Return type:

pandas.DataFrame

unithon.write_df_all_houses(df_, output_path='.//', frequency=60)

This function writes in a csv the dataframes of all houses.

Parameters:
  • df (pandas.DataFrame) – dataframes of all houses.
  • output_path (str, optional) – relative output path.
  • frequency (int, optional) – refresh frequency in minutes of the output.
Returns:

The function returns True if the operation is successful.

Return type:

bool