+ 6

Chessboard in pandas without gaps

I tried to create a chessboard as pd DataFrame. But I dont find a good solution to get the fields without gaps. Finally I want the middle one but without havint to print the Dataframe row by row https://sololearn.com/compiler-playground/cINjPImL8T42/?ref=app

19th Mar 2024, 7:53 AM
Oma Falk
Oma Falk - avatar
4 Réponses
+ 4
One more idea: merge all the columns to a single string. combined = cb.agg(''.join, axis=1)
19th Mar 2024, 8:32 AM
Tibor Santa
Tibor Santa - avatar
+ 2
I don't see a benefit of a data frame here. For nice printing, see my comment on your "corners" code.
19th Mar 2024, 8:34 AM
Lisa
Lisa - avatar
+ 2
Also if you stick with the numpy array, you can condense the output with an empty separator: print("I dont like the gaps") for row in cb: print(*row, sep='')
19th Mar 2024, 8:38 AM
Tibor Santa
Tibor Santa - avatar
+ 1
I don't think you can do it in the console. Here is all the formatting options built into pandas. I did not find anything related to column separator. https://pandas.pydata.org/pandas-docs/stable/user_guide/options.html Maybe if you print to html, you might be able to apply some custom CSS to remove the padding, margin and border from table cells.
19th Mar 2024, 8:24 AM
Tibor Santa
Tibor Santa - avatar