[英]How to add csv files to a pandas dataframe present in Azure file share using python
[英]How to read the files of Azure file share as csv that is pandas dataframe
我的 Azure 文件共享中有几个 csv 文件,我通过以下代码以文本形式访问这些文件:
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)
正在显示 csv 文件的内容,但我需要将它们作为 dataframe 传递,但我无法做到。 谁能告诉我如何将 file.content 读取为 pandas dataframe?
从我这边复制后,我可以按照以下代码从文件内容中将 csv 文件读入 dataframe。
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)
结果:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.