<jupyter_start><jupyter_text>Run experiments to store data in azure storage blob.<jupyter_code>from io import BytesIO
from azure.storage.blob import BlobClient
import os<jupyter_output><empty_output><jupyter_text>Get a BlobClient with the specified blob name<jupyter_code>bc = BlobClient.from_connection_string(
    conn_str = os.environ['BLOB_CONNECTION_STR'],
    container_name = os.environ['CONTAINER_NAME'],
    blob_name = 'my.parquet'
)
bc<jupyter_output><empty_output><jupyter_text>Create a pandas data frame for storage<jupyter_code>import pyarrow as pa
import pandas as pd

data = {'Name':['Tom', 'nick', 'krish', 'jack'], 'Age':[20, 21, 19, 18]} 
df = pd.DataFrame(data, index = ('i1', 'i2', 'i3', 'i4'))<jupyter_output><empty_output><jupyter_text>Create a pyarrow table from pandas data frame<jupyter_code>output_table = pa.Table.from_pandas(df)
output_table.schema<jupyter_output><empty_output><jupyter_text>Write the pyarrow table as parquet and store it in azure<jupyter_code>#%%

import pyarrow.parquet as pq

try:
    outputstream = BytesIO()
    pq.write_table(output_table, outputstream)
    bc.upload_blob(outputstream.getvalue())
finally:
    outputstream.close()<jupyter_output><empty_output><jupyter_text>Read the schema back from the blob store<jupyter_code>try:
    input_blob = bc.download_blob()
    inputstream = BytesIO()
    input_blob.download_to_stream(inputstream)
    input_table = pq.read_table(source=inputstream)
finally:
    inputstream.close()<jupyter_output><empty_output><jupyter_text>Assert that the schema are the same<jupyter_code>assert output_table.schema == input_table.schema
print('Source and target parquet are identical!')<jupyter_output>Source and target parquet are identical!<jupyter_text>Print out the table content as pandas data frame<jupyter_code>pdf = input_table.to_pandas()
pdf<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10599571734475374, 'fraction_numerical': 0.006423982869379015, 'mean_word_length': 7.197368421052632, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '263871', 'license': 'Apache-2.0', 'n_tokens_mistral': 665, 'n_tokens_neox': 652, 'n_words': 138, 'path': 'src/griff4/azure/azblobstore.ipynb', 'repo_name': 'mtzavellas/griff4', 'size': '1868'}