Q:

How to remove unwanted row spaces in a table in pptx using python-pptx?

I would like to remove the unwanted spaces in between the rows so it becomes compact like below screencap:

I tried to use space_before and space_after but it didn't work. Any suggestion?
bdy_cells[i].text_frame.paragraphs[0].space_before = Pt(2)
bdy_cells[i].text_frame.paragraphs[0].space_after = Pt(2)

Shown below are the arrows which contains spaces

A:

python-pptx allows the _Cell margins to be specified: https://python-pptx.readthedocs.io/en/latest/api/table.html#pptx.table._Cell.margin_top
So you might have something like:
from pptx.util import Inches

for cell in row.cells:
    cell.margin_top = Inches(0)
    cell.margin_bottom = Inches(0)

By default, the top and bottom cell margins are 0.05 inches.

