Posts

Python/Pandas Resources

http://pandas.pydata.org/ pandas-docs/stable/10min.html https://www.reddit.com/r/ learnpython/comments/4n3xkv/ learning_to_use_pandas/ http://queirozf.com/entries/ pandas-dataframe-by-example http://queirozf.com/tag/ python/

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 g...

7/6/17 Notes (Trying to find total attendance)

I want to add a command that will add all the numbers in the attendance column together for one person. I tried this command I found online: StudentinfoAll.loc[StudentinfoAll['Full Name'] == 'Ella Hubbell', 'Attendance'].sum() I got an error saying “Attendance’ is not in the columns” but is a column header I looked at the chart that I made and there are multiple Attendance columns so I tried typing “Attendance_x” instead. This didn’t add them it just put the numbers together into the number “10109” I tried this command instead: StudentinfoAll.sum(axis = {‘Georgianna Bamberger’,'Attendance_x'} skipna=None) This did not work. I deleted the skipna part because it was “invalid syntax” I got an error saying this was “unhashable” so I changed the format of the cells in the Attendance file to “text” and reuploaded the file. This did not worked. I replaced Georgianna Bamberger’s name, and ‘Attendance’ with the numbers that co...

7/5/17 Notes (Adding a column with the year in it and merging all the files together)

Trying to make a column in the confidences14 dataframe that has “2013-14” in each cell. I tried a command I found online here is what I typed: ConfidenceS14['Year'] = Series(np.random.randn(sLength), index=ConfidenceS14.index) I got an error saying “series” was not defined, I’m not sure what I should put there I tried putting ‘Year’ where series was and ‘[39]’ where sLength was (# of rows) this gave me an error that said “need integer” Tried changing command to this: ConfidenceS14['Year'] = 'Year'([2013-14]([39]), index=ConfidenceS14.index) I got an error that says “ 'list' object is not callable ” I tried a simpler command I found online and it worked! ConfidenceS14['Year'] = '2013-14' Merged ConfidenceS14 with ConfidenceS15 here is the command I used Confidence1415 = pd.merge(left=ConfidenceS14,right=ConfidenceS15, on=['First Name','Last Name'], how='outer') I used an ...

Getting Code to Match up Misspelled Names

This code changes misspelled names to the correct spelling so when the code merges the two files together, the names will match up. ***SM has to be >.95 (this number was found testing different names that had extra spaces) i=0 j=0 for rows in AttS14['First Name']:     print rows     for rws in Attendance['First Name']:         print 'Attendance',rws         if(SM(None,rows,rws).ratio()>0.95):             print rows,rws,SM(None,rows,rws).ratio()             AttS14.loc[i,'First Name']=rws             print AttS14.loc[i,'First Name']                     j=j+1     i=i+1 AttS14

6/3/17 Notes (Trying to get SM to replace misspelled names)

Trying to get the rstrip function to work Tried str.rstrip() this did not work Tried str.rstrip(“ “) this did not work Tried str.rstrip(‘ ‘) this did not work Tried str.rstrip ( ) this did not work Tried adding lstrip too, this did not work I made a practice notebook with two simple csv files. I couldn’t get the strip function to work so instead of having extra spaces at the end of the name I added 8 so I could see if the function was working or not and I found that it was not deleting the 8s I tried this command just to see if it would work: Str = “Rachel8” str.strip(8) This worked so I need to find a way to set str equal to the file I want to open. I could not find a way to get str to open the file I wanted to so instead I tried this command: for line in Space['Full Name'].readlines():    cleaned_line = line.replace(" ","") cleaned_line This did not work I tried typing “for line in Space.readlines(...