extra_streamlit_tools.data

Module Contents

extra_streamlit_tools.data.series_to_value(series_value: pandas.Series) Any

The series_to_value function takes a pandas series and returns the value of that series. If there is more than one row in the series, it raises an error.

Parameters:

series_value (pd.Series) – Pass the series object to the function

Returns:

A single value from a pd.Series

Return type:

Any

Examples

>>> series_to_value(pd.Series([1]))
1
>>> series_to_value(pd.Series([1, 2]))
ValueError: Found more than one row
extra_streamlit_tools.data.get_unique_sorted_values(df: pandas.DataFrame, column: str, astype: Type = str) list[Any]

The get_unique_sorted_values function returns a list of sorted unique values for the given column.

Parameters:
  • df (pd.DataFrame) – Specify the dataframe that is used in the function

  • column (str) – Specify the column name of the dataframe to get the values from

  • astype (Type=str) – Specify the type to convert the values to

Returns:

A list of unique and sorted values for a given column

Return type:

list[Any]

Examples

>>> df = pd.DataFrame({'col1': ['a', 'b', 'c'], 'col2': [1, 2, 3]})
>>> get_unique_sorted_values(df, 'col1')
['a', 'b', 'c']
>>> get_unique_sorted_values(df, 'col2', astype=float)
[1.0, 2.0, 3.0]
extra_streamlit_tools.data.get_values_based_on_other_value(df: pandas.DataFrame, based_column: str, based_value: any, new_values_column: str) list[any]

The get_values_based_on_other_value function takes a dataframe, a column name, and a value. It returns the unique values of another column in the same dataframe where that first column has the given value.

Parameters:
  • df (pd.DataFrame) – Specify the dataframe that is being used

  • based_column (str) – Specify the column that will be used to filter the dataframe

  • based_value (any) – Specify the value that is used to filter the based column with

  • new_values_column (str) – Specify the column that we want to get values from

Returns:

The values in the new_values_column column

Return type:

list[any]

Examples

>>> df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': ['a', 'b', 'c']})
>>> get_values_based_on_other_value(df, 'A', 1, 'C')
['a']
>>> get_values_based_on_other_value(df, 'B', 6, 'C')
['c']
extra_streamlit_tools.data.get_concat_columns(df: pandas.DataFrame, columns, join_with: str) list[str]

The get_concat_columns function takes a dataframe, a list of columns to concatenate, and the string to join them with. It returns a list of strings that are the concatenated values from each row in the specified columns.

Parameters:
  • df (pd.DataFrame) – Specify the dataframe that is being passed into the function

  • columns – Specify the columns that will be concatenated

  • join_with (str) – Specify the join string that will be used to join the row values into a string

Returns:

A list of strings

Return type:

list[str]

Examples

>>> df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': ['a', 'b', 'c']})
>>> get_concat_columns(df, ['A', 'B'], '-')
['1-4', '2-5', '3-6']
>>> get_concat_columns(df, ['A', 'C'], '.')
['1.a', '2.b', '3.c']