简体   繁体   中英

How to read the files of Azure file share as csv that is pandas dataframe

I have few csv files in my Azure File share which I am accessing as text by following the code:

from azure.storage.file import FileService

storageAccount='...'
accountKey='...'

file_service = FileService(account_name=storageAccount, account_key=accountKey)

share_name = '...'
directory_name = '...'
file_name = 'Name.csv'
file = file_service.get_file_to_text(share_name, directory_name, file_name)
print(file.content)

The contents of the csv files are being displayed but I need to pass them as dataframe which I am not able to do. Can anyone please tell me how to read the file.content as pandas dataframe?

After reproducing from my end, I could able to read a csv file into dataframe from the contents of the file following the below code.

generator = file_service.list_directories_and_files('fileshare/')
for file_or_dir in generator:
    print(file_or_dir.name)
    file=file_service.get_file_to_text('fileshare','',file_or_dir.name)
    df = pd.read_csv(StringIO(file.content), sep=',')
    print(df)

RESULTS:

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM