Ashraf Khaled
Ashraf Khaled

Reputation: 91

Saving multiple dataframes to multiple text filles

I want to save a list of dataframes each dataframe in a text file, I've tried this snippet but I got an error.

for entry in os.listdir(basepath):
    if os.path.isfile(os.path.join(basepath, entry)):
        list2.append(entry)

for df in list1:
    df.to_csv("E:/test2/" + entry for entry in list2, index = False)

df.to_csv("E:/test2/" + entry for entry in list2, index = False) ^ SyntaxError: Generator expression must be parenthesized if not sole argument

What can I do?

Upvotes: 0

Views: 34

Answers (1)

Mukarram Pasha
Mukarram Pasha

Reputation: 368

Try this:

for df, entry in zip(list1, list2):
    df.to_csv("E:/test2/" + entry, index=False)

Upvotes: 3

Related Questions