Python Forum
How to move each team row to a new column. Pandas
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to move each team row to a new column. Pandas
#1
Have a question how to move each team row to a new column dataset. So, I have 10 strings for 1 game and need to move this strings to columns to make dataframe look like this and for every stat.


 df = pd.DataFrame({'Team1':'[teamname]' , 'Team2':'[teamname]' ,
    'Score1': [0], 'Score2': [2],'team1_Player1_KD': [1], 'team1_Player2_KD': [2],'team1_Player3_KD': [1], 'team1_Player4_KD': [2],'team1_Player5_KD': [2],
'team2_Player1_KD': [2],'team2_Player2_KD': [1], 'team2_Player3_KD': [2],'team2_Player4_KD': [2],
'team2_Player5_KD': [2]})
And my final dataset should look like 1 string per match with 200+ columns with player stats. But now have 25 columns for player and 5 string with player stat of 1 team and 2nd team.

Have thoughts, its needed to make function that convert it, but Im new with python, so.. need help.

   

I leave link to main dataframe.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  HTML Decoder pandas dataframe column mbrown009 3 932 Sep-29-2023, 05:56 PM
Last Post: deanhystad
  pandas column percentile nuncio 7 2,357 Aug-10-2022, 04:41 AM
Last Post: nuncio
  pandas: Compute the % of the unique values in a column JaneTan 1 1,747 Oct-25-2021, 07:55 PM
Last Post: jefsummers
  Pandas Data frame column condition check based on length of the value aditi06 1 2,637 Jul-28-2021, 11:08 AM
Last Post: jefsummers
  iretate over columns in df and calculate euclidean distance with one column in pandas Pit292 0 3,250 May-09-2021, 06:46 PM
Last Post: Pit292
Question Pandas - Creating additional column in dataframe from another column Azureaus 2 2,898 Jan-11-2021, 09:53 PM
Last Post: Azureaus
  Pandas: summing columns conditional on the column labels ddd2332 0 2,063 Sep-10-2020, 05:58 PM
Last Post: ddd2332
  Pandas DataFrame and unmatched column sritsv19 0 2,979 Jul-07-2020, 12:52 PM
Last Post: sritsv19
  Pandas - Dynamic column aggregation based on another column theroadbacktonature 0 2,985 Apr-17-2020, 04:54 PM
Last Post: theroadbacktonature
  Add column to CSV using Pandas nsadams87xx 2 2,746 Apr-15-2020, 08:41 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020