-1

I have a column with N row like this

Column A
1
2
..
..
..
999,999
1,000,000

I want outcome like this: ('1','2','3',...,'1000') ('1001','1002',...,'2000') ...

each list contains 1000 value and separate exactly like that.

snakecharmerb
  • 47,570
  • 11
  • 100
  • 153
Annn
  • 1

2 Answers2

0

If you have a Python list named my_list you can use:

chunk = 1000
new_list = [my_list[i:i+chunk] for i in range(0, len(my_list), chunk)]

I am not clear about the format of your items, but assuming they are numbers and you want to convert to a list of strings as you seem to indicate then you could use something like the code below and then export to CSV.

result = []  
 
for item in new_list:
    x = [str(y) for y in item]
    result.append(x)
user19077881
  • 3,643
  • 2
  • 3
  • 14
  • I got the idea, but how can i export them to csv or excel file with 1 list in 1 cell, example like i have a colimn with 6877 row, make it 7 list, i need them in 7 cell in csv or excel , tks – Annn Dec 05 '22 at 10:57
  • @Annn Please don't move the target: How to export something is _not at all_ part of your stated question. Think long and hard about what you want to ask, then ask it well, and stick to it (apart from minor adjustments). Anything beyond that should be a new question. – Timus Dec 05 '22 at 11:49
  • I've modified my answer to convert the format, but in-line with @Titmus exporting is another coding question. – user19077881 Dec 05 '22 at 11:57
-1

If you are parsing a CSV, I would suggest you using the pandas lib like this:

import pandas as pd

df_groups = pd.read_csv('data.csv', chunksize=1000)

for group in df_groups:
    print(group)

This will print each group of 1000 rows to the console. You can then process each group of data as needed.

Dylan Delobel
  • 786
  • 10
  • 26
  • OP didn't say they were parsing a CSV, they say they have a list... – AKX Dec 05 '22 at 10:36
  • 1
    @snakecharmerb Which doesn't mean they've just read these million integers from a CSV file though :) – AKX Dec 05 '22 at 11:05