user14360121
user14360121

Reputation:

ValueError: No objects to concatenate

I m trying to merge different txt. I want to create different Dataset for every different target.

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'

And it works for the first 5 lines, it creates a DataFrame called A with the right values and labels, but then for the second and the third Dataframe (b and c) I obtain this error:

ValueError: No objects to concatenate

Someone can help me here? Thank you so much!

Upvotes: 0

Views: 10979

Answers (1)

rjg
rjg

Reputation: 579

First, you are iterating over all_files (unknown) and not all_files1. So that might explain why the first 5 lines work.

Then, you are on a Windows filesystem, so the hierarchy delimiter is \ and not /, you should use os.path.join instead (so you don't have to worry about the user's filesystem):

import os
all_files1 = glob.glob(os.path.join(path1, "*.csv"))

Upvotes: 3

Related Questions