我需要在Python的pandas dataframe中左对齐一个描述列。类似于在Excel表格中左对齐或右对齐单元格。是否有解决方案?附带参考图片。
!数据集
试试这个
df.style.set_properties(subset=["col1", "col2"], **{'text-align': 'right'})
我认为你可以直接删除前导空格。
df.Description = df.Description.apply(lambda row: row.lstrip(' '))