From pandas.DataFrame documention :
, ( ). . . pandas
, . "\n" DataFrame.
'pos' "" . "pos" , . :
pos bidder
0 1
1 2
2 3 <- alice
3 <- bob
4 5
, , "", 4, "bob". , . , DataFrame , , , .
.
import pandas as pd
n = 5
output = pd.DataFrame({'pos': range(1, n + 1),
'bidder': [''] * n},
columns=['pos', 'bidder'])
bids = {'alice': 3, 'bob': 3}
used_pos = []
for bidder, pos in bids.items():
if pos in used_pos:
output.ix[pos, 'bidder'] = "<- %s" % bidder
output.ix[pos, 'pos'] = ''
else:
output.ix[pos - 1, 'bidder'] = "<- %s" % bidder
used_pos.append(pos)
print(output)
Edit:
.
pos /
. DataFrame NaN
.
import pandas as pd
data = {'johnny\nnewline': 2, 'alice': 3, 'bob': 3,
'frank': 4, 'lisa': 1, 'tom': 8}
n = range(1, max(data.values()) + 1)
output = pd.DataFrame(columns=n, index=[])
for index, (bidder, pos) in enumerate(data.items()):
output.loc[index, pos] = bidder
print(output.fillna(''))
for index in range(1, 5):
print(output.loc[index, 2])
, . :)