I have a Pandas DataFrame in which one of the columns contains string elements, and those string elements contain new lines that I would like to print literally. But they just appear as
in the output.
That is, I want to print this:
pos bidder
0 1
1 2
2 3 <- alice
<- bob
3 4
but this is what I get:
pos bidder
0 1
1 2
2 3 <- alice
<- bob
3 4
How can I accomplish what I want? Can I use a DataFrame, or will I have to revert to manually printing padded columns one row at a time?
Here's what I have so far:
n = 4
output = pd.DataFrame({
'pos': range(1, n+1),
'bidder': [''] * n
})
bids = {'alice': 3, 'bob': 3}
used_pos = []
for bidder, pos in bids.items():
if pos in used_pos:
arrow = output.ix[pos, 'bidder']
output.ix[pos, 'bidder'] = arrow + "
<- %s" % bidder
else:
output.ix[pos, 'bidder'] = "<- %s" % bidder
print(output)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…