i have the following dataset:
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
i want to folder them accordingly their S and A columns like this
DATA\S1\A1
DATA\S1\A2
DATA\S2\A1
and I only want the corresponding XYZ values in my csv file
I have tried this piece of code. Creation of the folders work but I cannot save the corresponding csv file to proper folder. How should I fix the issue
df is list that containing 3 different 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

