3

Some cells of my SQLite table exceed the length of pandas display settings in the terminal. Is there a way to make a long cell of information word-wrap to another line?

Here is my code:

def view_work(self, CID):
    pd.set_option('display.max_columns', None)
    sq="SELECT * FROM Work_Done WHERE CID=?;"
    df=pd.read_sql_query(sq, self.conn, params=CID)
    df=df.set_index("Date")
    df=df.sort_values(by=['Date'])
    return df

Here is the current DataFrame output:

Date                                                Work_Done Parts_Installed /                   
2018-12-20  Installed computer and removed all of the pre-...                   
2018-12-22  Worked on getting Antivirus instlaled. Set up ...            None    

What I want is:

Date                                                Work_Done Parts_Installed /                   
2018-12-20  Installed computer and removed all of the pre-
            installed software. Joined computer to domain 
            and setup network applications for user.           
2018-12-22  Worked on getting Antivirus installed. Set up a  
            printer/fax machine. Loaded software for user and
            showed them how to use the computer.                          None    

Is it possible to word-wrap my 'Work_Done' cells when they exceed the maximum length of display?

John Harris
  • 361
  • 3
  • 6

1 Answers1

-1

pd.set_option('display.max_colwidth', None) should do the work for you. It will set the column width to unlimited with no overflows (which means without "..." but with automatic linebreaks). Check in the pandas docs.

Jakub Siwiec
  • 428
  • 4
  • 13