diff --git a/README.md b/README.md index 2b0a601..6d2daac 100644 --- a/README.md +++ b/README.md @@ -5,11 +5,6 @@ It is a fork of *truths* by [tr3buchet](https://github.com/tr3buchet/truths). ![Multiple outputs](https://raw.githubusercontent.com/chicolucio/truth-table-generator/master/images/ttg_small.png) -[![Build Status](https://travis-ci.com/chicolucio/truth-table-generator.svg?branch=master)](https://travis-ci.com/chicolucio/truth-table-generator) -[![Updates](https://pyup.io/repos/github/chicolucio/truth-table-generator/shield.svg)](https://pyup.io/repos/github/chicolucio/truth-table-generator/) -[![Python 3](https://pyup.io/repos/github/chicolucio/truth-table-generator/python-3-shield.svg)](https://pyup.io/repos/github/chicolucio/truth-table-generator/) -[![codecov](https://codecov.io/gh/chicolucio/truth-table-generator/branch/master/graph/badge.svg)](https://codecov.io/gh/chicolucio/truth-table-generator) - It merges some of the pull requests in the original and other external helpers. The following are some of the changes and enhancements from the original: @@ -208,14 +203,11 @@ print(table.as_tabulate(index=False, table_format='latex')) ### Formatting options with Pandas With an IPython terminal or a Jupyter Notebook, it is possible to render a Pandas -DataFrame with `table.as_pandas()`: +DataFrame with `table.as_pandas`: ![pandas01](https://raw.githubusercontent.com/chicolucio/truth-table-generator/master/images/pandas01.png) -And this output can be modified with Pandas Styling - -![pandas02](https://raw.githubusercontent.com/chicolucio/truth-table-generator/master/images/pandas02.png) - +And this output can be modified with Pandas Styling. More advanced modifications can be done with functions that apply styling changes. See the [styles tutorial notebook](styling_tutorial.ipynb) for examples. See the image below for a fancy example with two lines and two columns @@ -248,7 +240,7 @@ table_val.valuation() ``` 'Tautology' ``` -If a integer is used as argument, the function classifies the correspondent +If an integer is used as argument, the function classifies the correspondent column: ```python table_val.valuation(3) diff --git a/images/pandas01.png b/images/pandas01.png index 55d7b0a..61fc75e 100644 Binary files a/images/pandas01.png and b/images/pandas01.png differ diff --git a/images/pandas02.png b/images/pandas02.png deleted file mode 100644 index d3467ec..0000000 Binary files a/images/pandas02.png and /dev/null differ diff --git a/styling_tutorial.ipynb b/styling_tutorial.ipynb index 0251faf..ff809e8 100644 --- a/styling_tutorial.ipynb +++ b/styling_tutorial.ipynb @@ -5,13 +5,13 @@ "execution_count": 1, "metadata": { "ExecuteTime": { - "end_time": "2019-10-19T22:56:14.903240Z", - "start_time": "2019-10-19T22:56:14.274689Z" + "end_time": "2020-05-04T14:49:13.079174Z", + "start_time": "2020-05-04T14:49:12.923639Z" } }, "outputs": [], "source": [ - "import ttg" + "import ttg\n" ] }, { @@ -26,8 +26,8 @@ "execution_count": 2, "metadata": { "ExecuteTime": { - "end_time": "2019-10-19T22:56:18.784843Z", - "start_time": "2019-10-19T22:56:18.780314Z" + "end_time": "2020-05-04T14:49:14.377957Z", + "start_time": "2020-05-04T14:49:14.361927Z" } }, "outputs": [], @@ -42,7 +42,7 @@ " \"\"\"Applies style to logical expression (logic) pandas truth table. \n", " Text: center. Table: no index column. Highlight yellow rows and columns in \n", " lists (hl_rows and hl_cols). At the end applies color_false_red function\"\"\"\n", - " d = logic.as_pandas().style.set_table_styles([{\n", + " d = logic.as_pandas.style.set_table_styles([{\n", " 'selector':\n", " 'th',\n", " 'props': [('font-size', '12pt')]\n", @@ -55,9 +55,9 @@ " axis=1).apply(lambda x: [\n", " 'background: lightyellow' if x.name in hl_cols else '' for i in x\n", " ],\n", - " axis=0).hide_index()\n", + " axis=0).hide(axis=\"index\")\n", " d = d.applymap(color_false_red)\n", - " return d" + " return d\n" ] }, { @@ -65,8 +65,8 @@ "execution_count": 3, "metadata": { "ExecuteTime": { - "end_time": "2019-10-19T22:56:21.878556Z", - "start_time": "2019-10-19T22:56:21.876005Z" + "end_time": "2020-05-04T14:49:15.506316Z", + "start_time": "2020-05-04T14:49:15.503400Z" } }, "outputs": [], @@ -74,7 +74,7 @@ "# creating a table\n", "table = ttg.Truths(['p', 'q'],\n", " ['p => q', 'q => p', '(p => q) and (q => p)', 'p = q'],\n", - " ints=False)" + " ints=False)\n" ] }, { @@ -82,198 +82,78 @@ "execution_count": 4, "metadata": { "ExecuteTime": { - "end_time": "2019-10-19T22:56:23.792037Z", - "start_time": "2019-10-19T22:56:23.353822Z" + "end_time": "2020-05-04T14:49:17.208345Z", + "start_time": "2020-05-04T14:49:16.446482Z" } }, "outputs": [ { "data": { "text/html": [ - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
p q p => q q => p (p => q) and (q => p) p = q
TrueTrueTrueTrueTrueTrue
TrueFalseFalseTrueFalseFalse
FalseTrueTrueFalseFalseFalse
FalseFalseTrueTrueTrueTrue
" + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
pqp => qq => p(p => q) and (q => p)p = q
TrueTrueTrueTrueTrueTrue
TrueFalseFalseTrueFalseFalse
FalseTrueTrueFalseFalseFalse
FalseFalseTrueTrueTrueTrue
\n" ], "text/plain": [ - "" + "" ] }, "execution_count": 4, @@ -283,7 +163,7 @@ ], "source": [ "# applying style. Without lists of rows and columns to highlight.\n", - "df_style(table)" + "df_style(table)\n" ] }, { @@ -291,198 +171,90 @@ "execution_count": 5, "metadata": { "ExecuteTime": { - "end_time": "2019-10-19T22:56:25.237456Z", - "start_time": "2019-10-19T22:56:25.196951Z" + "end_time": "2020-05-04T14:49:19.598051Z", + "start_time": "2020-05-04T14:49:19.552370Z" } }, "outputs": [ { "data": { "text/html": [ - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
p q p => q q => p (p => q) and (q => p) p = q
TrueTrueTrueTrueTrueTrue
TrueFalseFalseTrueFalseFalse
FalseTrueTrueFalseFalseFalse
FalseFalseTrueTrueTrueTrue
" + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
pqp => qq => p(p => q) and (q => p)p = q
TrueTrueTrueTrueTrueTrue
TrueFalseFalseTrueFalseFalse
FalseTrueTrueFalseFalseFalse
FalseFalseTrueTrueTrueTrue
\n" ], "text/plain": [ - "" + "" ] }, "execution_count": 5, @@ -492,7 +264,7 @@ ], "source": [ "# highlighting rows 2 and 4\n", - "df_style(table, hl_rows=[2, 4])" + "df_style(table, hl_rows=[2, 4])\n" ] }, { @@ -500,198 +272,90 @@ "execution_count": 6, "metadata": { "ExecuteTime": { - "end_time": "2019-10-19T22:56:27.571749Z", - "start_time": "2019-10-19T22:56:27.532171Z" + "end_time": "2020-05-04T14:49:22.703718Z", + "start_time": "2020-05-04T14:49:22.657043Z" } }, "outputs": [ { "data": { "text/html": [ - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
p q p => q q => p (p => q) and (q => p) p = q
TrueTrueTrueTrueTrueTrue
TrueFalseFalseTrueFalseFalse
FalseTrueTrueFalseFalseFalse
FalseFalseTrueTrueTrueTrue
" + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
pqp => qq => p(p => q) and (q => p)p = q
TrueTrueTrueTrueTrueTrue
TrueFalseFalseTrueFalseFalse
FalseTrueTrueFalseFalseFalse
FalseFalseTrueTrueTrueTrue
\n" ], "text/plain": [ - "" + "" ] }, "execution_count": 6, @@ -701,7 +365,7 @@ ], "source": [ "# highlighting columns named 'p' and 'p = q'\n", - "df_style(table, hl_cols=['p', 'p = q'])" + "df_style(table, hl_cols=['p', 'p = q'])\n" ] }, { @@ -709,198 +373,104 @@ "execution_count": 7, "metadata": { "ExecuteTime": { - "end_time": "2019-10-19T22:56:28.932431Z", - "start_time": "2019-10-19T22:56:28.891944Z" + "end_time": "2020-05-04T14:49:23.627714Z", + "start_time": "2020-05-04T14:49:23.569356Z" } }, "outputs": [ { "data": { "text/html": [ - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
p q p => q q => p (p => q) and (q => p) p = q
TrueTrueTrueTrueTrueTrue
TrueFalseFalseTrueFalseFalse
FalseTrueTrueFalseFalseFalse
FalseFalseTrueTrueTrueTrue
" + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
pqp => qq => p(p => q) and (q => p)p = q
TrueTrueTrueTrueTrueTrue
TrueFalseFalseTrueFalseFalse
FalseTrueTrueFalseFalseFalse
FalseFalseTrueTrueTrueTrue
\n" ], "text/plain": [ - "" + "" ] }, "execution_count": 7, @@ -910,7 +480,7 @@ ], "source": [ "# highlighting rowns and columns\n", - "df_style(table, hl_rows = [2, 4], hl_cols=['p', 'p = q'])" + "df_style(table, hl_rows = [2, 4], hl_cols=['p', 'p = q'])\n" ] }, { @@ -924,9 +494,9 @@ "metadata": { "hide_input": false, "kernelspec": { - "display_name": "Python [conda env:ttg]", + "display_name": "ttg", "language": "python", - "name": "conda-env-ttg-py" + "name": "python3" }, "language_info": { "codemirror_mode": { @@ -938,7 +508,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.4" + "version": "3.11.1" }, "toc": { "base_numbering": 1,