6

Have to left align a description column in the pandas dataframe in python. Similar to left or right align a cell in excel sheet. is there any solution for this? Image attached for reference.

!Dataset

4
  • Try giving some more detail about the specifics of your problem and what you've tried. It's not clear exactly what the screenshot is showing and what you're trying to achieve Commented Nov 24, 2018 at 18:01
  • Description column in the dataset is right aligned. I just need left align it. Like how we use in excel left align,right align a cell. Commented Nov 24, 2018 at 18:06
  • a pandas DataFrame is an in memory table structure so has no concept of alignment. It looks like you're displaying it in some way but not clear in your question/screenshot how this is being done. So it's likely a display setting you need to change Commented Nov 24, 2018 at 18:08
  • Okay understood. Thank you. I have updated the question and image. Commented Nov 24, 2018 at 18:26

2 Answers 2

5

Try this

df.style.set_properties(subset=["col1", "col2"], **{'text-align': 'right'})
Sign up to request clarification or add additional context in comments.

Comments

-1

I think you can just remove the leading spaces.

df.Description = df.Description.apply(lambda row: row.lstrip(' '))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.