1

I have two data sets: grades.csv and rubric.csv

A sample from the grades csv is below:

Student ID,Question 1,Question 2,Question 3,Question 4,Question 5,Question 6
205842,6.5,6.5,9.5,5.5,3.5,9.5
280642,8.5,9.5,3.5,9.5,4,9.5

and the rubric csv looks like this:

Question,Max score
Question 1, 20
Question 2, 10
Question 3, 10
Question 4, 15
Question 5, 10
Question 6, 25

I want to be able to add the 'Max Score' column from the rubric csv as another column in the grades csv.

So far I have the below. I am assuming the grades.csv needs to be deconstructed or inverted for t

grades_df = pd.read_csv(grades)
rubric_df = pd.read_csv(rubric)
grades_dft = grades_df.T
TC1111
  • 89
  • 8
  • how do u want it to appear? max for each question or max for each student? an example of ur expected output would help in understanding your question. – sammywemmy Feb 08 '20 at 01:10
  • It's the maximum per question, hence why I was thinking it needs to be transposed first. My thinking is that once you have the max score by question you should be able to transpose it back. – TC1111 Feb 08 '20 at 01:14

1 Answers1

1

Just assign it like this:

grades_df = pd.read_csv(grades)
rubric_df = pd.read_csv(rubric)
grades_df['Max score'] = rubric_df['Max score']
print(grades_df)

Or if you want to be very explicit adding a new column like @jakub mention:

grades_df.loc[:, 'Max_score'] = rubric_df['Max score']

You will get this:

   Student ID  Question 1  Question 2  Question 3  Question 4  Question 5  Question 6  Max score
0      205842         6.5         6.5         9.5         5.5         3.5         9.5         20
1      280642         8.5         9.5         3.5         9.5         4.0         9.5         10
marcos
  • 4,473
  • 1
  • 10
  • 24
  • I would suggest using `grades_df.loc[:, 'Max_score']` instead of `grades_df['Max_score']` to be more explicit. – jkr Feb 08 '20 at 01:09
  • @jakub, true, I will add it to the answer. – marcos Feb 08 '20 at 01:10
  • @jakub I'm not sure I understand, how is that more explicit? – AMC Feb 08 '20 at 01:54
  • @AMC - this answer summarizes why: https://stackoverflow.com/a/38886211/5666087 – jkr Feb 08 '20 at 02:02
  • Thanks for your help, however this adds max score only to the first 6 rows and also to Student ID - instead of Max Score being allocated by question which is what I am after – TC1111 Feb 08 '20 at 02:09