diff --git a/README.md b/README.md index 8048f23..e20dc6a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Mecsimcalc v0.1.4 documentation +# Mecsimcalc v0.1.5 documentation This library is designed to provide a set of functions for handling and converting various types of data, such as base64 encoded data, Pandas DataFrames, and Pillow images. @@ -311,6 +311,7 @@ Create a DataFrame from given rows and column headers | -------------------- | ------------------- | ------------------------------------------------------------------------------- | | **`column_headers`** | **List[str]** | List of column headers | | **`rows`** | **List[List[str]]** | List of rows to be converted into a DataFrame. Each column is a list of strings | +| **`index`** | **bool** (optional) | Whether to use the first column as the DataFrame's index. (Defaults to True) | #### Returns: @@ -346,10 +347,11 @@ Creates an HTML table from given rows and column headers #### Arguments: -| Argument | Type | Description | -| -------------------- | ------------------- | --------------------------------------------------------------------------- | -| **`column_headers`** | **List[str]** | List of column headers | -| **`rows`** | **List[List[str]]** | List of rows to be converted into a table. Each column is a list of strings | +| Argument | Type | Description | +| -------------------- | ------------------- | ---------------------------------------------------------------------------- | +| **`column_headers`** | **List[str]** | List of column headers | +| **`rows`** | **List[List[str]]** | List of rows to be converted into a table. Each column is a list of strings | +| **`index`** | **bool** (optional) | Whether to use the first column as the DataFrame's index. (Defaults to True) | #### Returns: diff --git a/mecsimcalc/table_utils.py b/mecsimcalc/table_utils.py index b5d93bb..8ccb3a3 100644 --- a/mecsimcalc/table_utils.py +++ b/mecsimcalc/table_utils.py @@ -3,7 +3,7 @@ def table_to_dataframe( - column_headers: List[str], rows: List[List[str]] + column_headers: List[str], rows: List[List[str]], index: bool = True ) -> pd.DataFrame: """ >>> table_to_dataframe(column_headers: List[str], rows: List[List[str]]) -> pd.DataFrame @@ -16,6 +16,8 @@ def table_to_dataframe( List of column headers. rows : List[List[str]] List of rows to be converted into a DataFrame. Each row is a list of strings. + index : bool + Whether to use the first column as the DataFrame's index. (Defaults to True) # Raises @@ -41,10 +43,12 @@ def table_to_dataframe( if len(row) != len(column_headers): raise ValueError("Each row must have the same length as the column headers") - return pd.DataFrame(rows, columns=column_headers) + return pd.DataFrame(rows, columns=column_headers, index=index) -def print_table(column_headers: List[str], rows: List[List[str]]) -> str: +def print_table( + column_headers: List[str], rows: List[List[str]], index: bool = True +) -> str: """ >>> print_table(column_headers: List[str], rows: List[List[str]]) -> str @@ -56,6 +60,8 @@ def print_table(column_headers: List[str], rows: List[List[str]]) -> str: The header for each column. rows : List[List[str]] A list of rows (each row is a list of strings). + index : bool + Whether to use the first column as the DataFrame's index. (Defaults to True) # Returns @@ -72,4 +78,4 @@ def print_table(column_headers: List[str], rows: List[List[str]]) -> str: """ df = table_to_dataframe(column_headers, rows) - return df.to_html(index=True, border=1, escape=True) + return df.to_html(index=index, border=1, escape=True) diff --git a/setup.py b/setup.py index ea433cd..0232345 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ with codecs.open(os.path.join(here, "README.md"), encoding="utf-8") as fh: long_description = "\n" + fh.read() -VERSION = "0.1.4" +VERSION = "0.1.5" DESCRIPTION = "Useful functions for MecSimCalc.com" # Setting up