python - ValueError:没有要连接的对象
问题描述
我正在尝试合并不同的txt。我想为每个不同的目标创建不同的数据集。
path1 = r'C:\Users\chiar\Desktop\Dataset\A' # use your path
all_files1 = glob.glob(path1 + "/*.csv")
name= ['quat_1', 'quat_2', 'quat_3', 'quat_4']
a = pd.concat((pd.read_csv(f, names=name) for f in all_files), ignore_index=True)
a['activity'] = 'A'
path2 = r'C:\Users\chiar\Desktop\TESI\Dataset\B' # use your path
all_files2 = glob.glob(path2 + "/*.csv")
name= ['quat_1', 'quat_2', 'quat_3', 'quat_4']
b = pd.concat((pd.read_csv(f, names=name) for f in all_files2), ignore_index=True)
b['activity'] = 'B'
path3 = r'C:\Users\chiar\Desktop\TESI\Dataset\C' # use your path
all_files3 = glob.glob(path3 + "/*.csv")
name= ['quat_1', 'quat_2', 'quat_3', 'quat_4']
c = pd.concat((pd.read_csv(f, names=name) for f in all_files3), ignore_index=True)
c['activity'] = 'C'
它适用于前 5 行,它使用正确的值和标签创建了一个名为 A 的 DataFrame,但是对于第二个和第三个 DataFrame(b 和 c),我得到了这个错误:
ValueError:没有要连接的对象
有人可以在这里帮助我吗?非常感谢!
解决方案
首先,您正在迭代all_files
(unknown) 而不是all_files1
. 所以这可以解释为什么前 5 行有效。
然后,你在一个 Windows 文件系统上,所以层次分隔符 is\
和 not /
,你应该os.path.join
改用(所以你不必担心用户的文件系统):
import os
all_files1 = glob.glob(os.path.join(path1, "*.csv"))
推荐阅读
- android - 如何在android中检测已经与设备连接的OTG电缆?
- android - 我想在 androidx 29 版本(最新版本)中导入设计库
- javascript - 如何从javascript发送具有2个值的表单?
- swift - 快速 NSPredicate 数据(结构)
- php - Doctrine LockMode::PESSIMISTIC 数据库重复
- jquery-ui - 自动完成:在悬停和按下向上和向下键时更改颜色
- python - 我想在某些条件下从列表 python 列表中创建一个列表,我提到了预期的输出
- python-3.x - “SalesforceBulk”对象没有属性“post_bulk_batch”
- xml - 将结构化 XML 国际邮寄地址格式化为文本
- c# - CSharpScript - TypeLoadException