In [2]:
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
tips_data = sns.load_dataset("tips")

#Show first five rows of data
print(tips_data)
# Create a histogram using Seaborn
sns.histplot(data=tips_data, x="total_bill", bins=20)
# Set plot title and axis labels
plt.title("Distribution of Bill Amount")
plt.xlabel("Total Bill")
plt.ylabel("Count")
# Display the plot
plt.show()
     total_bill   tip     sex smoker   day    time  size
0         16.99  1.01  Female     No   Sun  Dinner     2
1         10.34  1.66    Male     No   Sun  Dinner     3
2         21.01  3.50    Male     No   Sun  Dinner     3
3         23.68  3.31    Male     No   Sun  Dinner     2
4         24.59  3.61  Female     No   Sun  Dinner     4
..          ...   ...     ...    ...   ...     ...   ...
239       29.03  5.92    Male     No   Sat  Dinner     3
240       27.18  2.00  Female    Yes   Sat  Dinner     2
241       22.67  2.00    Male    Yes   Sat  Dinner     2
242       17.82  1.75    Male     No   Sat  Dinner     2
243       18.78  3.00  Female     No  Thur  Dinner     2

[244 rows x 7 columns]
No description has been provided for this image
In [3]:
tips = sns.load_dataset("tips")
# Create a bar chart of the count of each day of the week in the dataset
sns.countplot(x="day", data=tips_data)
plt.title("Tip Count by Day")
plt.xlabel("Day")
plt.ylabel("Count")
Out[3]:
Text(0, 0.5, 'Count')
No description has been provided for this image
In [4]:
# Create a line chart of the total bill by day
sns.lineplot(x="day", y="total_bill", data=tips_data)
# Set the title and axis labels
plt.title("Total Bill by Day")
plt.xlabel("Day")
plt.ylabel("Total Bill")
# Display the plot
plt.show()
No description has been provided for this image
In [5]:
# Create scatter plot of total_bill vs. tip
sns.scatterplot(data=tips_data, x="total_bill", y="tip")
# Set the title and axis labels
plt.title("Relationship between Bill Amount and Tip Amount")
plt.xlabel("Bill Amount")
plt.ylabel("Tip Amount")
# Show the plot
plt.show()
No description has been provided for this image
In [6]:
# Create a pivot table of the total_bill and tip variables
table = tips_data.pivot_table(values="tip", index="day", columns="size")
# Create a heatmap using the pivot table
sns.heatmap(table, cmap="YlGnBu")
# Set the title and axis labels
plt.title("Average Tip Given on Each Day")
plt.xlabel("Average Tip Amount")
plt.ylabel("Day")
# display the plot
plt.show()
/tmp/ipykernel_3032/297347880.py:2: FutureWarning: The default value of observed=False is deprecated and will change to observed=True in a future version of pandas. Specify observed=False to silence this warning and retain the current behavior
  table = tips_data.pivot_table(values="tip", index="day", columns="size")
No description has been provided for this image
In [7]:
# Create a box plot for the total_bill column
sns.boxplot(x=tips_data['total_bill'])
plt.xlabel("Total Bill")
# Display the plot
plt.show()
No description has been provided for this image
In [8]:
 # Create a box plot of the total bill amount by day of the week
sns.boxplot(x="day", y="total_bill", data=tips_data)
# Set the title and axis labels
plt.title("Distribution of Bill Amount by Day of the Week")
plt.xlabel("Day Amount")
plt.ylabel("Bill Amount")
# Show the plot
plt.show()
No description has been provided for this image
In [10]:
# Create a frequency table of the size variable
freq_table = pd.crosstab(index=tips_data["size"], columns="count")
# Print the frequency table
print(freq_table)
col_0  count
size        
1          4
2        156
3         38
4         37
5          5
6          4
In [12]:
# Create a correlation matrix of the numerical variables in the dataset
corr_matrix = tips_data.corr()
# Display the correlation matrix
print(corr_matrix)
            total_bill       tip      size
total_bill    1.000000  0.675734  0.598315
tip           0.675734  1.000000  0.489299
size          0.598315  0.489299  1.000000
In [13]:
# create a crosstab of sex and smoker variables
cross_tab = pd.crosstab(tips_data['sex'], tips_data['smoker'])
# display the crosstab
print(cross_tab)
smoker  Yes  No
sex            
Male     60  97
Female   33  54
In [14]:
from scipy.stats import chi2_contingency
# Create crosstabulation of sex and smoker
cross_tab = pd.crosstab(tips['sex'], tips['smoker'])
# Perform chi-square test
chi2, pval, dof, expected = chi2_contingency(cross_tab)
# print the results
print("Chi-square statistic:", chi2)
print("p-value:", pval)
Chi-square statistic: 0.0
p-value: 1.0
In [ ]:
 
In [1]:
!jupyter nbconvert --to html bana320_dataunderstanding.ipynb
Traceback (most recent call last):
  File "/usr/local/lib/python3.13/dist-packages/jsonschema/_format.py", line 304, in <module>
    import rfc3987
ModuleNotFoundError: No module named 'rfc3987'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/jupyter-nbconvert", line 4, in <module>
    from nbconvert.nbconvertapp import main
  File "/usr/local/lib/python3.13/dist-packages/nbconvert/__init__.py", line 6, in <module>
    from . import filters, postprocessors, preprocessors, writers
  File "/usr/local/lib/python3.13/dist-packages/nbconvert/filters/__init__.py", line 8, in <module>
    from .markdown import (
    ...<6 lines>...
    )
  File "/usr/local/lib/python3.13/dist-packages/nbconvert/filters/markdown.py", line 16, in <module>
    from .markdown_mistune import markdown2html_mistune
  File "/usr/local/lib/python3.13/dist-packages/nbconvert/filters/markdown_mistune.py", line 23, in <module>
    from nbconvert.filters.strings import add_anchor
  File "/usr/local/lib/python3.13/dist-packages/nbconvert/filters/strings.py", line 23, in <module>
    from nbconvert.preprocessors.sanitize import _get_default_css_sanitizer
  File "/usr/local/lib/python3.13/dist-packages/nbconvert/preprocessors/__init__.py", line 3, in <module>
    from nbclient.exceptions import CellExecutionError
  File "/usr/local/lib/python3.13/dist-packages/nbclient/__init__.py", line 2, in <module>
    from .client import NotebookClient, execute
  File "/usr/local/lib/python3.13/dist-packages/nbclient/client.py", line 19, in <module>
    from nbformat import NotebookNode
  File "/usr/local/lib/python3.13/dist-packages/nbformat/__init__.py", line 14, in <module>
    from . import v1, v2, v3, v4
  File "/usr/local/lib/python3.13/dist-packages/nbformat/v4/__init__.py", line 24, in <module>
    from .convert import downgrade, upgrade
  File "/usr/local/lib/python3.13/dist-packages/nbformat/v4/convert.py", line 12, in <module>
    from nbformat import v3, validator
  File "/usr/local/lib/python3.13/dist-packages/nbformat/validator.py", line 17, in <module>
    from .json_compat import ValidationError, _validator_for_name, get_current_validator
  File "/usr/local/lib/python3.13/dist-packages/nbformat/json_compat.py", line 13, in <module>
    import jsonschema
  File "/usr/local/lib/python3.13/dist-packages/jsonschema/__init__.py", line 13, in <module>
    from jsonschema._format import FormatChecker
  File "/usr/local/lib/python3.13/dist-packages/jsonschema/_format.py", line 328, in <module>
    from rfc3987_syntax import is_valid_syntax as _rfc3987_is_valid_syntax
  File "/usr/local/lib/python3.13/dist-packages/rfc3987_syntax/__init__.py", line 1, in <module>
    from .syntax_helpers import *
  File "/usr/local/lib/python3.13/dist-packages/rfc3987_syntax/syntax_helpers.py", line 102, in <module>
    is_valid_syntax_ipath_absolute = make_syntax_validator("ipath_absolute")
  File "/usr/local/lib/python3.13/dist-packages/rfc3987_syntax/syntax_helpers.py", line 66, in make_syntax_validator
    parser = Lark(grammar, start=rule_name, parser=RFC3987_SYNTAX_PARSER_TYPE)
  File "/usr/local/lib/python3.13/dist-packages/lark/lark.py", line 374, in __init__
    self.grammar, used_files = load_grammar(grammar, self.source_path, self.options.import_paths, self.options.keep_all_tokens)
                               ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/dist-packages/lark/load_grammar.py", line 1416, in load_grammar
    builder.load_grammar(grammar, source)
    ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/dist-packages/lark/load_grammar.py", line 1241, in load_grammar
    tree = _parse_grammar(grammar_text, grammar_name)
  File "/usr/local/lib/python3.13/dist-packages/lark/load_grammar.py", line 968, in _parse_grammar
    tree = _get_parser().parse(text + '\n', start)
  File "/usr/local/lib/python3.13/dist-packages/lark/parser_frontends.py", line 131, in parse
    return self.parser.parse(stream, chosen_start, **kw)
           ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/dist-packages/lark/parsers/lalr_parser.py", line 42, in parse
    return self.parser.parse(lexer, start)
           ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/dist-packages/lark/parsers/lalr_parser.py", line 88, in parse
    return self.parse_from_state(parser_state)
           ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/dist-packages/lark/parsers/lalr_parser.py", line 102, in parse_from_state
    state.feed_token(token)
    ~~~~~~~~~~~~~~~~^^^^^^^
  File "/usr/local/lib/python3.13/dist-packages/lark/parsers/lalr_parser_state.py", line 101, in feed_token
    value = callbacks[rule](s) if callbacks else s
            ~~~~~~~~~~~~~~~^^^
  File "/usr/local/lib/python3.13/dist-packages/lark/parse_tree_builder.py", line 152, in __call__
    filtered = children[i].children
    ^^^^^^^^
KeyboardInterrupt
^C
In [ ]: