我编写了以下代码来从共享文件中保存的文件创建数据帧。它非常适用于 excel 文件,但对于 csv 文件失败并出现错误EmptyDataError: No columns to parse from file。
tblname = 'test'
fPth = r'Z:\Favorites\test10 (Group D - Custom EM&V)\8 PII\16 - Project Selection Plan\QC\Data\test.csv'
sht = 'Gross_Data'
shtStart = 0
fType = 'csv'
fitem = sfsession.get_io_version(fPth)
if fitem is None:
print(f'Could not create sharefile item for {fPth}')
else:
try:
if fType == 'csv':
df = pd.read_csv(fitem.io_data, header = shtStart)
elif fType == 'excel':
df = pd.read_excel(fitem.io_data, sheet_name = sht, header = shtStart)
else:
pass
print(f'Data import COMPLETE for {fPth}: {str(datetime.now())}')
except:
print(f'Data import FAILED for {fPth}')
logging.critical(f'Data import FAILED for {fPth}')
如果我在df = pd.read_csv中用fPth替换fitem.io_data,则代码有效,但我不能将其用作永久解决方案。有什么建议么?
sfsession 也是一个共享文件会话,get_io_version(fPth) 获取令牌并下载所有文件属性,包括其数据。谢谢。