<jupyter_start><jupyter_text>Fugue demo<jupyter_code># Enable Fugue SQL by loading "fugue_notebook" extension
%load_ext fugue_notebook
# Or include this line instead, it is another way to load "fugue_notebook" extension
from fugue_notebook import setup
setup()<jupyter_output><empty_output><jupyter_text>__NOTE__ When using fugue SQL you might see warnings. Ignore them. Or run the next cell to supress warnings<jupyter_code># Supress warnings
import warnings
warnings.filterwarnings('ignore')<jupyter_output><empty_output><jupyter_text>Load CSV file into pandas dataframe<jupyter_code>import pandas as pd
df = pd.read_csv('housing.csv') 
# Display pandas dataframe (standard visualization)
df<jupyter_output><empty_output><jupyter_text>Query pandas dataframe with Fugue SQLQuery and display the output<jupyter_code>%%fsql
df2 = SELECT * FROM df LIMIT 2
PRINT<jupyter_output><empty_output><jupyter_text>Complex query with self-join<jupyter_code>%%fsql
SELECT df.crim, df.zn, df.ptratio, df2.nox, df2.age, df2.tax, df2.medv 
FROM df 
JOIN df AS df2 ON df.age = df2.age
LIMIT 15
PRINT<jupyter_output>UsageError: Cell magic `%%fsql` not found.<jupyter_text>Query and save to Fugue frame<jupyter_code>%%fsql
SELECT df.crim, df.zn, df.ptratio, df2.nox, df2.age, df2.tax, df2.medv 
FROM df 
JOIN df AS df2 ON df.age = df2.age
LIMIT 15
YIELD DATAFRAME AS fugue_df<jupyter_output><empty_output><jupyter_text>Transform Fugue frame itno pandas dataframe<jupyter_code>ndf = fugue_df.as_pandas()
ndf<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08899143045484509, 'fraction_numerical': 0.011865524060646011, 'mean_word_length': 7.161290322580645, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '182990', 'license': 'Apache-2.0', 'n_tokens_mistral': 582, 'n_tokens_neox': 565, 'n_words': 147, 'path': 'experimental/notebook-workspace/tutorials/sql-pandas.ipynb', 'repo_name': 'Tiamat-Tech/alnoda-workspaces', 'size': '1517'}