0

I have few csv files present in Azure file shares which I have to put it in pandas dataframe using python and do some operations.

The below code gets the data from containers:

dbutils.fs.mount(
  source = "abfss://"+ container + "@" + storageAccountName + ".dfs.core.windows.net",
  mount_point = "/mnt/" + container,
  extra_configs = {'fs.azure.account.auth.type.' + storageAccountName + '.dfs.core.windows.net': "SharedKey",
                   'fs.azure.account.key.' +       storageAccountName + '.dfs.core.windows.net': storageAccountAccessKey})

But my files are not present in containers. They are under file shares. Can anyone please help me how to get data from Azure file share using python

Pratik Lad
  • 4,343
  • 2
  • 3
  • 11
Akshata
  • 111
  • 5
  • 2
    Does this answer your question? [Databricks and Azure Files](https://stackoverflow.com/questions/55617970/databricks-and-azure-files) – yurib Nov 14 '22 at 20:22

1 Answers1

0

As yurib Suggested to read data from Azure file share To databricks python we need to install Azure Storage File module.

  • To install Azure Storage File module, you need to use: pip install azure-storage-file enter image description here

  • After module is installed, you follow the below code to load the Azure Files to Azure Databricks.

from azure.storage.file import FilePermissions, FileService
from datetime import datetime, timedelta 

url_sas_token="https://{account_name}.file.core.windows.net/{share_name}/{file_name}?{sas_token}"

import pandas as pd
pdf = pd.read_csv(url_sas_token)
df = spark.createDataFrame(pdf)
df.show()

Execution And Output:

enter image description here

Pratik Lad
  • 4,343
  • 2
  • 3
  • 11