7/7/17 Notes(Changing the names of classes in the data frame)

Trying to edit the names of classes so that they appear as their STEM code in the dataframe
  • I tried using the “maketrantab” function but this doesn’t work because the strings have to be the same length so I can’t translate a word into one letter with this.
  • Tried this command (Space is the file because I’m using a smaller file to see if it works before I add it to the real code):
    • Space.replace(value=dict{'Classes':{'art':'H'}})
    • “{” was invalid syntax so I replaced it with parenthesis.
    • I got an error saying : was invalid syntax so I deleted it
    • Now I’m getting an error saying my string isn’t callable
  • Tried this command:
    • Space['Classes'] = Space['Classes'].map({'art': 'H'})
    • This didn’t give me an error but when I tried to display the classes column I got all “Nan” values
    • I tried coding letters for all the classes instead of just one (I have a list of classes in one column. This did not work I still got NaN values in the classes column.
    • I tried changing the format of my file so that each class was in an individual column, then using this command:
      • Space['Am1'] = Space['Am1'].map({'English':'H'})
      • This still gave me NaN values in all the cells in “Am1” even the ones I didn’t try to change.
      • I tried writing code to change all the class names. This did not work.
      • I tried switching the order of the classes, and their new name (I wrote ‘H’: ‘English’ instead of ‘English’: ‘H’ this did not work.
    • Tried just typing “Space['Am1'].map({'English':'H','physics':'SP','math':'M'})” this had no effect, I still got the class names
    • Tried this command I found online
      • Space.Am1.replace(to_replace=dict(English=H, math=M, physics=SP), inplace=True)
      • I got an error saying H was not defined so I put apostrophes around all the letters. This worked!
    • I tried merging the class columns into one “Classes” column, and then translating the class names. This did not work so I will have to translate the names before I merge them into one column.

Comments

Popular posts from this blog

6/14/17 Notes

6/06/17 Notes (formatting code and searching for a specific person)

May 22, 2017 -- SienaSemanticsSurvey -- Code Breakdown -- Cell #8