Working on a dataframe without loading it into memory

I have a dataframe with slightly more than half a million rows. The columns hold very small values, so the dataframe is easily stored in memory.

However on the other hand, I have around 700GB of data, spread into 50-row chunks of binary files, corresponding to each row of my dataframe. So given a row from my small-sized dataframe, I’m able to access the corresponding column value from the 700GB “dataset”.

What I want to do is to create one single CSV file from all of these and some additional data that I will produce for each row.

For context, here’s the access function and the generator function that I’ve coded for retrieving a column value from my 700GB data set given a row index:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>filenames = os.listdir("/content/drive/MyDrive/ProteiNNGO_Data/") # The folder that has the chunks
def get_embedding_chunk(index, old_chunk_start):
# The chunks are stored with this name pattern, including the start and end indices
pattern = re.compile(r'^(?:embeddingsssss_|featuress_)(d+)_(d+)$')
for filename in filenames:
match = pattern.match(filename)
if match:
start, end = int(match.group(1)), int(match.group(2))
# If we are accessing data that is in the same chunk as before, don't load it again
if start == old_chunk_start:
return None, start
# Otherwise, if we're in the right chunk, load the chunk
if start <= index < end:
with open(f"/content/drive/MyDrive/ProteiNNGO_Data/{filename}", "rb") as f:
return pickle.load(f), start
</code>
<code>filenames = os.listdir("/content/drive/MyDrive/ProteiNNGO_Data/") # The folder that has the chunks def get_embedding_chunk(index, old_chunk_start): # The chunks are stored with this name pattern, including the start and end indices pattern = re.compile(r'^(?:embeddingsssss_|featuress_)(d+)_(d+)$') for filename in filenames: match = pattern.match(filename) if match: start, end = int(match.group(1)), int(match.group(2)) # If we are accessing data that is in the same chunk as before, don't load it again if start == old_chunk_start: return None, start # Otherwise, if we're in the right chunk, load the chunk if start <= index < end: with open(f"/content/drive/MyDrive/ProteiNNGO_Data/{filename}", "rb") as f: return pickle.load(f), start </code>
filenames = os.listdir("/content/drive/MyDrive/ProteiNNGO_Data/") # The folder that has the chunks
def get_embedding_chunk(index, old_chunk_start):
  # The chunks are stored with this name pattern, including the start and end indices
  pattern = re.compile(r'^(?:embeddingsssss_|featuress_)(d+)_(d+)$')
  for filename in filenames:
    match = pattern.match(filename)
    if match:
      start, end = int(match.group(1)), int(match.group(2))
      # If we are accessing data that is in the same chunk as before, don't load it again
      if start == old_chunk_start:
        return None, start

      # Otherwise, if we're in the right chunk, load the chunk
      if start <= index < end:
        with open(f"/content/drive/MyDrive/ProteiNNGO_Data/{filename}", "rb") as f:
          return pickle.load(f), start

And here’s a generator that I coded that will efficiently iterate over rows

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>def embedding_generator():
chunk = None
start = -1
for i in range(len(sequences)):
new_chunk, new_start = get_embedding_chunk(i, start)
start = new_start
if new_chunk is not None:
del chunk
chunk = new_chunk
offset = i - start
yield i, chunk[offset]
gc.collect()
</code>
<code>def embedding_generator(): chunk = None start = -1 for i in range(len(sequences)): new_chunk, new_start = get_embedding_chunk(i, start) start = new_start if new_chunk is not None: del chunk chunk = new_chunk offset = i - start yield i, chunk[offset] gc.collect() </code>
def embedding_generator():
  chunk = None
  start = -1
  for i in range(len(sequences)):
    new_chunk, new_start = get_embedding_chunk(i, start)
    start = new_start
    if new_chunk is not None:
      del chunk
      chunk = new_chunk
    offset = i - start
    yield i, chunk[offset]
    gc.collect()

How can I use this iterator and add each row to a dataframe without having the entire dataframe in the memory?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật