0

I'm very new to Python and am sure its something small I'm doing incorrectly, but I just cannot figure this out. I created a new column "POSITION" that is equal to the first 2 digits of the "POS" column just to extract the alpha characters, but it only returns for the first 2 records then starts returning NaN. And even for those its pulling the full value instead of the first 2 digits. Any isnight on what I am doing wrong, or how I can obtain my goal is greatly appreciated.

FF_2022 = pd.read_csv("C:/Users/balestre/Downloads/FantasyPros_2022_Draft_ALL_Rankings.csv")

FF_2022['POSITION'] = FF_2022["POS"][0:2]
       
print(FF_2022)

Output:

      RK  TIERS          PLAYER NAME TEAM    POS  BEST  WORST   AVG.  STD.DEV ECR VS. ADP POSITION
0      1      1      Jonathan Taylor  IND    RB1     1      2    1.0      0.1           0      RB1
1      2      1        Derrick Henry  TEN    RB2     2      4    2.8      0.7          +4      RB2
2      3      1        Austin Ekeler  LAC    RB3     2     10    4.2      1.8          -1      NaN
3      4      1          Dalvin Cook  MIN    RB4     2      9    4.8      1.5          +3      NaN
4      5      1  Christian McCaffrey  CAR    RB5     2     12    5.0      3.1          -1      NaN
..   ...    ...                  ...  ...    ...   ...    ...    ...      ...         ...      ...
447  448     16         Samori Toure   GB  WR148   341    342  341.5      0.5           -      NaN
448  449     16        Tyler Huntley  BAL   QB48   343    355  349.0      6.0           -      NaN
449  450     16       Antoine Wesley  ARI  WR149   336    369  352.5     16.5           -      NaN
450  451     16          Tutu Atwell  LAR  WR150   329    387  358.0     29.0           -      NaN
451  452     16            Bo Melton  SEA  WR151   364    378  371.0      7.0           -      NaN

[452 rows x 11 columns]
TrevB
  • 40
  • 3
  • 1
    You're so close! Just use the `str` accessor to slice from _each_ string -> `FF_2022['POSITION'] = FF_2022["POS"].str[0:2]` – Henry Ecker May 12 '22 at 19:16

0 Answers0