I would like to keep this same code but adjust the .to_csv section to save a variable repeating file name
JavaScript
x
3
1
for i in range(round(len(usersDf)/577)):
2
usersDf.loc[i*577:(i+1)*577,:].to_csv('Stored_files_'+str(i)+'.csv')
3
I would like the names of the exported files to look like this…I think I need some sort of loop?
Period 1 layer 1.csv
Period 1 layer 2.csv
Period 1 layer 3.csv
Period 1 layer 4.csv
Period 1 layer 5.csv
Period 2 layer 1.csv
Period 2 layer 2.csv
Period 2 layer 3.csv
Period 2 layer 4.csv
Period 2 layer 5.csv
Period 3 layer 1.csv
And so on….till the loop ends
Advertisement
Answer
JavaScript
1
8
1
no_of_periods = 577
2
no_of_layers = 5
3
for i in range(no_of_periods):
4
for j in range(no_of_layers):
5
filename = f"Period {i+1} layer {j+1}.csv"
6
#print(filename)
7
usersDf.loc[i*577:(i+1)*577,:].to_csv(filename)
8
You can try this one out.