I have a script that creates many pandas data frames that look like this:
Name Position Team Salary Projection Opponent
4 Andy Isabella WR ARI 4500 14.440124 CAR
6 Kyler Murray QB ARI 7000 70.585769 CAR
7 DeAndre Hopkins WR ARI 8500 24.701569 CAR
9 Ravens DST BAL 4000 25.095681 WAS
14 Mark Andrews TE BAL 6000 26.201007 WAS
32 Mike Davis RB CAR 5700 20.394783 ARI
34 Cordarrelle Patterson WR CHI 3700 20.315333 IND
79 Will Fuller WR HOU 5900 26.891008 MIN
110 Malcolm Brown RB LAR 4700 18.767278 NYG
Sometimes there will be 4 players of position "WR" and 2 "RB" and others there will be 3 players of position "WR" and 3 "RB". But there will always be exactly 9 players with 1 QB, 1 TE, and 1 DST
the function i have written to write this pandas dataframe to a csv file is below:
def write_csv():
df2 = pd.DataFrame()
for name, df in my_team.items():
df2 = df2.append(df)
df2.to_csv('test.csv', mode='a')
What I want to do is have it append the pandas dataframe to the csv file in a specific order based off column "Position". the order I want is based off of the person's "position" value and i want to go as follows:
- QB
- RB
- RB
- WR
- WR
- WR
- TE
- WR or RB (based off if there is an extra person of position RB or WR)
- DST
How would I do this?