Merging First/Last Name Columns and Changing First Name to Just First Initial

A bit of a complicated question here, so I will try to be as precise as possible.

I am working with two different data sets:

  1. qb.metrics.df
  2. roster.df

I would like to merge the two together. Typically, I would use left_join but there are no similar attributes among the two data sets.

Here is a look at qb.metrics.df ...

 Rank PlayerPlayerId   PlayerShortName       PlayerAgeExact PassAttemptsPer~ PassingYards CompletionPerce~ PassingTouchdow~
   <dbl>          <dbl> <chr>                    <dbl> <chr>            <chr>        <chr>            <chr>           
 1     1          20889 K. Murray                 23.3 34.6             2375         68.2             17              
 2     2          19801 J. Allen                  24.5 36.4             2873         68.4             21              
 3     3          14536 R. Wilson                 32   37.1             2789         69.8             28              
 4     4          18890 P. Mahomes                25.2 36.6             2687         66.9             25              
 5     5           2593 A. Rodgers                37   34.9             2578         67.8             26              
 6     6           4314 T. Brady                  43.3 38.5             2739         66               23              
 7     7          18857 D. Watson                 25.2 33.4             2539         68.1             18              
 8     8          21681 J. Herbert                22.7 37.6             2333         66.8             19              
 9     9          19781 L. Jackson                23.9 27.4             1762         64               14              
10    10          16497 T. Bridgewater            28   33.1             2544         71.9             13              

And here is a look at roster.df ...

 season team  position depth_chart_pos~ jersey_number status full_name first_name last_name birth_date height weight
    <dbl> <chr> <chr>    <chr>                    <int> <chr>  <chr>     <chr>      <chr>     <date>     <chr>  <chr> 
 1   2020 ARI   C        C                           52 Active Mason Co~ Mason      Cole      1996-03-28 6-5    292   
 2   2020 ARI   C        C                           53 Active Lamont G~ Lamont     Gaillard  1996-02-08 6-3    305   
 3   2020 ARI   CB       NB                          33 Active Byron Mu~ Byron      Murphy    1998-01-18 5-11   190   
 4   2020 ARI   CB       NA                          20 Active Prince A~ Prince     Amukamara 1989-06-06 6-0    204   
 5   2020 ARI   CB       NA                          39 Active Jace Whi~ Jace       Whittaker 1995-07-16 5-11   185   
 6   2020 ARI   CB       NA                          27 Injur~ Kevin Pe~ Kevin      Peterson  1994-03-22 5-11   185   
 7   2020 ARI   CB       LCB                         25 Active Johnatha~ Johnathan  Joseph    1984-04-16 5-11   185   
 8   2020 ARI   CB       NA                          23 Injur~ Robert A~ Robert     Alford    1988-10-31 5-10   186   
 9   2020 ARI   CB       LCB                         21 Active Patrick ~ Patrick    Peterson  1990-07-11 6-1    203   
10   2020 ARI   CB       RCB                         20 Active Dre Kirk~ Dre        Kirkpatr~ 1989-10-26 6-2    190 

I think the way to handle this is to simply edit the 'full_name' column in roster.df to match the 'PlayerShortName' column in qb.metrics.df.

Doing so would require editing the first name to just the first initial and then adding a '.'

Not sure how to go about that.

Any help in doing so would be greatly appreciated. As well, I am more than happy to entertain other ways to go about it.



Read more here: https://stackoverflow.com/questions/64939797/merging-first-last-name-columns-and-changing-first-name-to-just-first-initial

Content Attribution

This content was originally published by bcongelio at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: