为什么Pandas Imports .CSV作为DataFrame,而Excel则为DICE?
我正在尝试将CSV和Excel(XLSX)导入处理,合并,计算...但是,当使用PANDAS导入每种情况时,我会得到不同的数据类型:
import pandas as pd
ach_data = pd.read_excel(r'C:\temp\SHC v0.34.xlsm', sheet_name=['ABA_Accounts'])
c2c_import = pd.read_csv(r'C:\temp\C2C Import File.csv')
print('Excel: ' + str(type(ach_data)))
print('CSV: ' + str(type(c2c_import)))
输出:输出:
Excel: <class 'dict'>
CSV: <class 'pandas.core.frame.DataFrame'>
有什么原因?
I'm trying to import a CSV and Excel (xlsx) to process, merge, compute... however, when using pandas to import each, I get different data types:
import pandas as pd
ach_data = pd.read_excel(r'C:\temp\SHC v0.34.xlsm', sheet_name=['ABA_Accounts'])
c2c_import = pd.read_csv(r'C:\temp\C2C Import File.csv')
print('Excel: ' + str(type(ach_data)))
print('CSV: ' + str(type(c2c_import)))
Output:
Excel: <class 'dict'>
CSV: <class 'pandas.core.frame.DataFrame'>
Any reason why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是因为您将列表传递到
sheet_name
参数,请使用sheet_name ='aba_accounts'
而不是:如果您阅读 documentation 关于返回的内容:
It's because you pass a list to
sheet_name
parameter, usesheet_name='ABA_Accounts'
instead:If you read the documentation about what is returned:
将列表指定为
Sheet_name
参数意味着您想从.xslm文件中读取多个图片作为dataframes的dict。文档的一个例子:
,如果您只需一个数据框,只需将其作为字符串传递: ='aba_accounts'。
Specifying a list as the
sheet_name
argument means that you want to read multiple sheets from the .xslm file as a dict of DataFrames.An example from the docs:
If you only want one dataframe, just pass it as a string:
sheet_name='ABA_Accounts'
.