我有以下数据集:
X Y Z S A
_ _ _ _ _
0 1 2 1 1
8 5 3 1 2
5 6 7 2 1
9 8 9 2 2
6 7 7 1 3
我想像这样将它们相应地文件夹它们的 S 和 A 列
DATA\S1\A1
DATA\S1\A2
DATA\S2\A1
我只想要我的 csv 文件中的相应 XYZ 值
我试过这段代码。文件夹的创建有效,但我无法将相应的 csv 文件保存到正确的文件夹中。我该如何解决这个问题
df 是包含 3 个不同 pandas-dataframes 的列表
def write2path(df):
path = getcwd()
subjects = ["subject%d"%i for i in range(1,31)]
activities = [str(i) for i in range(1,7)]
try:
path = path + "\\DATA"
mkdir(path)
for l in subjects:
temp_path = path +"\\"+ l
mkdir(temp_path)
for k in activities:
temp_path_child = temp_path +"\\" + k
mkdir(temp_path_child)
for j in range(len(df)):
ch='x'
for i, x in df[j].loc[(['Subject0'] == int(l[7])) & (['Activity0'] == int(k))]:
print(x)
val=chr(ord(ch)+j)
x.to_csv(temp_path_child+"\\"+f'sensor-{val}.csv', index=False)
return self._engine.get_loc(self._maybe_cast_indexer(key))
File "pandas\_libs\index.pyx", line 111, in pandas._libs.index.IndexEngine.get_loc
File "pandas\_libs\index.pyx", line 135, in pandas._libs.index.IndexEngine.get_loc
File "pandas\_libs\index_class_helper.pxi", line 109, in pandas._libs.index.Int64Engine._check_type
KeyError: False
慕慕森
Smart猫小萌
相关分类