-2

I have been trying to print a new column in my dataframe that shows all of the courses a faculty is instructing for the month. However, I've only been able to find a way for the code to display one of the courses a faculty is instructing. My attempts to display all of them lead to additional fluff around the course codes. How can I remove the fluff?

 for name, group in grouped:
    num_students = group['RegStudents'].sum()
    num_sections = group['code'].count()
    course_code = group['code'].unique() #This displays all of the courses they teach but with fluff
    course_code_str = ', '.join(course_code.astype(str)) # my attempt to remove the fluff 

  ......

# This is the output 
['Ashley Tisdale',
  'ACD', #Faculty Title
  'MCBS', # Home program
  array(['MCB359', 'MED119'], dtype=object), # Course Codes with fluff 
  'This faculty is fully utilized.'],
  • 1
    Your question needs a minimal reproducible example consisting of sample input, expected output, actual output, and only the relevant code necessary to reproduce the problem. See [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) for best practices related to Pandas questions. Specifically, what does the input look like, what do you define as fluff, What do you want as the output and what are you getting? – itprorh66 Jun 27 '23 at 15:58
  • Please edit your question to include debugging information (i.e., what you tried). See [How to Ask](https://stackoverflow.com/help/how-to-ask) in the Stack Overflow FAQ. – zurgeg Jun 27 '23 at 17:05
  • I exported the code to excel and can see now that the text 'array' and 'dtype = object' are not showing, originally it was. So, the problem is essentially fixed. I would just like to remove the brackets and the quotation marks around the course code. – MSDataAnalyst75 Jun 27 '23 at 17:52

1 Answers1

0

group['code'].unique() returns a numpy array. You need to convert it to a built-in list, it seems:

list(group['code'].unique())

Maria K
  • 1,491
  • 1
  • 3
  • 14
  • I was able to export it to excel and see that the text 'array' and 'dtype = object' is not showing, originally it was. I would just like to remove the brackets and the quotation marks. – MSDataAnalyst75 Jun 27 '23 at 17:52