I have dataframe where my resulting output columns doesn't aligned correctly as requited and that's basically a column called UID which i need to align right.
I have tried Styler but that's not working.
MY code:
from io import BytesIO
import subprocess
import pandas as pd
from IPython.display import display
######################
lcmd='ldapsearch -x -LLL -b "ou=Functional,ou=People,ou=dtc,o=dtc"'
result = subprocess.check_output(lcmd, shell=True)
buffer = BytesIO(result)
df = pd.read_csv(filepath_or_buffer = buffer, header=None, names=['LoginShell', 'ExpiryDate', 'UID'])
df = df.applymap(lambda x: x.split(': ')[-1])
df = df[df.columns[::-1]]
print(df.head())
Result Output:
UID ExpiryDate LoginShell
0 auto_soc 20991212 /bin/bash
1 sambakul 20991212 /bin/bash
2 services2go-jenkins 20991212 /bin/bash
3 rdtest0 20991212 /bin/bash
4 sudo 20991212 /bin/bash
What i tried:
>>> df.style.set_properties(**{'text-align': 'left'})
<pandas.io.formats.style.Styler object at 0x7f052c2998d0>
or
>>> df.style.set_properties(subset=["UID", "ExpiryDate", "LoginShell"], **{'text-align': 'left'})
<pandas.io.formats.style.Styler object at 0x7f052b226fd0>
Expected:
UID ExpiryDate LoginShell
0 auto_soc 20991212 /bin/bash
1 sambakul 20991212 /bin/bash
2 services2go-jenkins 20991212 /bin/bash
3 rdtest0 20991212 /bin/bash
4 sudo 20991212 /bin/bash
My pandas Version:
>>> pd.__version__
'1.1.5'
I am using this code on my Linux machine(RedHat7)
df.style.