python_3 question: Does anyone can help me write this codes in a for loop:
df_0 = df[0:100]
df_1 = df[100:200]
df_2 = df[200:300]
.
.
df_n = df[n*100:len(df.index)]
python_3 question: Does anyone can help me write this codes in a for loop:
df_0 = df[0:100]
df_1 = df[100:200]
df_2 = df[200:300]
.
.
df_n = df[n*100:len(df.index)]
You can try this,
for i in range(0, len(df) + 1, 100):
locals()[f'df_{int(i / 100)}'] = df[i: i + 100]
print(df_0)
print(df_1)
But before using the locals()
method, it may be useful to read: https://stackoverflow.com/a/24197790/8205554
And I agree with eva-vw's comment. It would be a better option.