#print first 3 similar games
i = 0
print('The 3 most recommended games to', name, 'are:\n')
for item in sorted_scores:
game_name = steam_and_description_df[steam_and_description_df.game_id == item[0]]
print(i+1, game_name)
i = i + 1
if i>2:
break
基于上面这段代码,类型错误发生在 game_name 行代码上。
sorted_scores 列表
[(21872, 0.48374701837130774), (11515, 0.47249500411533485), (1623, 0.45933532497253254), (26951, 0.45573150915006005), (2929, 0.4544628310118689), (2902, 0.45233551503959735), (21275, 0.45160322552800564), (6485, 0.4494019003569672), (18721, 0.4493295836140727), (20464, 0.44814093729587356), (1326, 0.44558589411900384), (3554, 0.44528310669254334), (484, 0.44317385265582554), (9862, 0.44190961366257975), (20380, 0.43996794991372373), (14599, 0.4373114243610174), (4955, 0.4328844472660066), (6472, 0.43171551382770684), (7126, 0.42777317464066944), (22454, 0.4271522829155004), (3410, 0.4269326251274042), (21182, 0.42652921604328786), (171, 0.42589781096171214), (3736, 0.42550532908850214), (15114, 0.4254465291937926), (13544, 0.42510317971074085), (24987, 0.42421505708449514), (1273, 0.42410801324765734), (163, 0.4240960994393835), (23955, 0.42266514977135616), (6419, 0.42263696226704894), (21864, 0.42206485242778047), (14483, 0.4220267461087165), (22450, 0.4219432263130382), (1105, 0.4218351111835161), (7264, 0.4209821886577657), (23887, 0.42031314624465277), (1332, 0.4198645242324752), (11104, 0.4190435412010168), (4274, 0.4188913814114361), (6666, 0.4173564041086213), (3693, 0.4169652359763997), (26532, 0.41676410953682813), (13139, 0.4167345511816124), (67, 0.41661513252335747), (203, 0.4165230768457668), (9900, 0.41631620346038), (4751, 0.41565474657798546), (8114, 0.41532313839884144), (5486, 0.4152042025242376), (6210, 0.41483481695494123), (3103, 0.4148085045905877), (1302, 0.4134559224189003), (3786, 0.4132979814795533), (23044, 0.41292733275039506), (23355, 0.41287001789524513), (7180, 0.41260035566948594), (10812, 0.4120026522918673), (11380, 0.4119672651150211), (7670, 0.41117173731206785), (5475, 0.411152392221655), (20424, 0.4110941833132201), (181, 0.41104596767039664), (546, 0.4109425554675847), (26332, 0.4107069175381574), (24497, 0.4106471108195314), (15343, 0.41039264541262993), (6616, 0.41021959487753734), (17525, 0.41018356961981745), (468, 0.4100760790091801), (16841, 0.4095624265040569), (323, 0.4092635136710355), (4557, 0.40926027763932415), (17387, 0.4086626969030762), (14020, 0.40858112510204303), (20405, 0.4084553567203099), (3309, 0.4082852543256077), (8553, 0.40792385647413887), (5761, 0.4076134079818193), (6691, 0.40756899755410925), (13015, 0.40742987396782426), (16957, 0.4072474698274307), (6496, 0.40723509023947496), (14490, 0.40723421075461286), (22594, 0.406900750002858), (5045, 0.40680892161821663), (9369, 0.4068074601386988), (25087, 0.4067326285437382), (17831, 0.40670102913556055), (26686, 0.40637645361791325), (6538, 0.4063239547842654), (14571, 0.40619269023079585), (68, 0.406117601970229), (3064, 0.4060045145683347), (5473, 0.4059997859889778), (16325, 0.4058424434593101), (1745, 0.40507204835014066), (2648, 0.4048289434390435), (7621, 0.40479908558274), (13822, 0.4046610288469533), (1567, 0.40434533764564856), (17462, 0.40429924058938455), (12, 0.40411096047206324), (3393, 0.40378838495442265), (3411, 0.4037237132151256), (9459, 0.40343927554580583), (7612, 0.4033783257323473), (14347, 0.40336523716313777), (5883, 0.40334055350510595), (341, 0.403112882335462), (16107, 0.4029710672302373), (969, 0.4029125606171325), (13993, 0.4028770063296113), (10838, 0.40273594501573884), (337, 0.4021402455525484), (1647, 0.40204130966736273), (1772, 0.40202933848594846), (24925, 0.40192516933477057), (2210, 0.4018133457268974), (7095, 0.40172002062379053), (4571, 0.4013939824743619), (1600, 0.4013353930081608), (13042, 0.400942794025819), (3305, 0.40077993885007746), (5644, 0.40077818091759665), (11550, 0.40045672493308887), (11793, 0.4002455405195208), (8667, 0.3999426462344592), (16093, 0.39989902520871207), (24862, 0.3998022852793553), (20127, 0.39977101947046867), (19, 0.39970794535495846), (25378, 0.39970493967252374), (2188, 0.39964035657249763), (15035, 0.3992037436389809), (22571, 0.39889399191574326), (13593, 0.39879124518530507), (8668, 0.39878498285678204), (26023, 0.39877225238734504), (9282, 0.39876658963208456), (18523, 0.3987487001758809), (10038, 0.39847931287981736), (3634, 0.39810422926320993)]
steam_and_description_df
steam_appid name release_date english developer publisher platforms required_age categories genres ... negative_ratings average_playtime median_playtime owners price detailed_description about_the_game short_description game_id important_features
0 10 Counter-Strike 2000-11-01 1 Valve Valve windows;mac;linux 0 Multi-player;Online Multi-Player;Local Multi-P... Action ... 3339 17612 317 10000000-20000000 7.19 Play the world's number 1 online action game. ... Play the world's number 1 online action game. ... Play the world's number 1 online action game. ... 0 Counter-Strike Valve Valve Multi-player;Online...
1 20 Team Fortress Classic 1999-04-01 1 Valve Valve windows;mac;linux 0 Multi-player;Online Multi-Player;Local Multi-P... Action ... 633 277 62 5000000-10000000 3.99 One of the most popular online action games of... One of the most popular online action games of... One of the most popular online action games of... 1 Team Fortress Classic Valve Valve Multi-player...
我得到了这个作为输出
The 3 most recommended games to Counter-Strike are:
steam_appid name release_date \
20611 807730 Draft Day Sports: College Basketball 2018 2018-03-13
english developer publisher platforms required_age \
20611 1 Wolverine Studios Wolverine Studios windows 0
categories genres ... negative_ratings \
20611 Single-player Indie;Simulation;Sports;Strategy ... 3
average_playtime median_playtime owners price \
20611 0 0 0-20000 11.39
detailed_description \
20611 Take control as head coach of your favorite co...
about_the_game \
20611 Take control as head coach of your favorite co...
short_description game_id \
20611 Draft Day Sports: College Basketball 2018 puts... 20611
important_features
20611 Draft Day Sports: College Basketball 2018 Wolv...
[1 rows x 23 columns]
steam_appid name release_date \
17896 729310 Draft Day Sports: College Basketball 2017 2017-11-14
english developer publisher platforms required_age \
17896 1 Wolverine Studios Wolverine Studios windows 0
categories genres \
17896 Single-player;Shared/Split Screen Indie;Simulation;Sports;Strategy
... negative_ratings average_playtime median_playtime owners \
17896 ... 4 0 0 0-20000
price detailed_description \
17896 3.99 Take control as head coach of your favorite co...
about_the_game \
17896 Take control as head coach of your favorite co...
short_description game_id \
17896 Draft Day Sports: College Basketball 2017 puts... 17896
important_features
17896 Draft Day Sports: College Basketball 2017 Wolv...
[1 rows x 23 columns]
steam_appid name release_date english \
16283 683600 Football Mogul 18 2017-09-19 1
developer publisher platforms required_age \
16283 Sports Mogul, Inc. Sports Mogul, Inc. windows 0
categories \
16283 Single-player;Shared/Split Screen;Steam Achiev...
genres ... negative_ratings \
16283 Casual;Simulation;Sports;Strategy ... 10
average_playtime median_playtime owners price \
16283 0 0 20000-50000 5.79
detailed_description \
16283 <strong><i>Football Mogul®</i></strong> begins...
about_the_game \
16283 <strong><i>Football Mogul®</i></strong> begins...
short_description game_id \
16283 Football Mogul 18 is the 16th version of the a... 16283
important_features
16283 Football Mogul 18 Sports Mogul, Inc. Sports Mo...
[1 rows x 23 columns]
In [120]:
1
但是我想只显示名称可以吗?我怎么能这样做,我只是在增加字数。 它显示了所有的列,但我只想显示游戏的名称在这段代码中可以吗?
答案 0 :(得分:0)
将以下代码用于您的任务,
#print first 3 similar games
i = 0
print('The 3 most recommended games to', name, 'are:\n')
for item in sorted_scores:
game_name = steam_and_description_df.loc[(steam_and_description_df.game_id == item[0]),['name']]
print(i+1, game_name)
i = i + 1
if i>2:
break