This problem sounds very simple and probably has a very easy solution. However, nothing I have tried works.
The file I am importing, 'bedwars.csv', has 29 rows. Each (comma-separated) row consists of a player and their point value: 'Player, Points'.
I have a list of 16 players, 'samplePlayers.csv', all of whom are also in 'bedwars.csv'. I am trying to remove the players that are NOT in 'sampleplayers.csv' from 'bedwars.csv'. FWIW the players in 'samplePlayers.csv' ae just the first 16 players in 'bedwars.csv'.
My attempt is below.
import pandas as pd
playing = pd.read_csv('samplePlayers.csv') # test data
# imports all past game data
bedwars = pd.read_csv('bedwars.csv')
bedwars.columns = ['Players', 'Points']
players = list(bedwars.Players)
points = list(bedwars.Points)
bedwarsPoints = list(zip(players, points))
print(bedwarsPoints)
for i in bedwarsPoints:
if i not in playing:
bedwarsPoints.remove(i)
print(bedwarsPoints)
Outputs the following:
[('Star_Dragon4', 40.88), ('LethalPilot', 32.18625), ('macrocosms', 27.4), ('mrjad333', 25.82142857), ('IceKing12323', 22.51666667), ('AllieThaDon', 20.568), ('SuperToad916', 18.675), ('odsstel', 18.04285714), ('NautilusReign', 17.6), ('14ham', 16.39), ('Hunter13004', 15.72), ('sapphronn', 15.44), ('SerRonanIrwin', 14.23333333), ('LightningLucario', 14.062), ('Dispuesto', 13.565), ('KirynMissy', 13.12285714), ('Abach6', 12.68857143), ('lurchlurger', 11.78), ('Labmonjo1210', 10.78), ('humilau', 9.65125), ('BYTECH', 9.57), ('de_eh', 9.3), ('cowDude12345', 8.65), ('Menderlovemybug', 8.5), ('tenparks', 8.366666667), ('TheUW', 6.8), ('QuinnQuimby', 5.2), ('stealthguy11', 4.05), ('Buck274', 0.0)]
[('LethalPilot', 32.18625), ('mrjad333', 25.82142857), ('AllieThaDon', 20.568), ('odsstel', 18.04285714), ('14ham', 16.39), ('sapphronn', 15.44), ('LightningLucario', 14.062), ('KirynMissy', 13.12285714), ('lurchlurger', 11.78), ('humilau', 9.65125), ('de_eh', 9.3), ('Menderlovemybug', 8.5), ('TheUW', 6.8), ('stealthguy11', 4.05)]
The first being an array of length 29 (good), the array from 'samplePlayers.csv'. The second, however, consists of the mangled remnants of the attempted removal. I noticed that the "for" loop has only been removing every other value.
Please let me know if any more clarification is needed and I will respond. Thank you all in advance for your help.