0

I am trying to assign reviewers to projects with the condition that the author of the project cannot be assigned as a reviewer to a project in their own portfolio.

I created a dataset with variables named project and portfolio. I have an array with the names of the individuals.

Please be kind, as I am learning Python on my own on the job, using Jupyter Notebook, python 3. I copied this code from other places and put it together. I have been at this all day. My superior wants error free code by the end of the week. I am desperate!!!

Here is the code that I have so far:

!pip install pandas
    dir_path = "path/to/filename.csv"    

import pandas as pd
df = pd.read_csv(dir_path,index_col=0)
df.head

import random
     random.seed(25, 2) #sets the first random number for reproducibility
     random.randint(100, 250) #random integer 100 to 250 

Update 1 (works, thanks Ken!):

import pandas as pd

# Load  dataframe
df = pd.read_csv(dir_path, index_col = 0)
first = df["portfolio"] 
print(first)     

Update2  # Select 6 random projects for Moi which are not "XXX"
#random dataframe
import numpy as py
df2 = pd.read_csv(dir_path, skiprows=1)
np.random.seed(100)
df2 = pd.DataFrame(np.random.randint(10, size=(6,2)), columns=list('project portfolio') if ((portfolio == "XYZ") or (portfolio == "ABC") or (portfolio == "MKZ") or (portfolio == "BNZ")) 
print (df2)   

Error message 
File "<ipython-input-29-0ee5224a45db>", line 7
    print (df2)
    ^
SyntaxError: invalid syntax

I daresay this is a simple mistake.

7
  • You're missing a ) at the end of the section with df1 =, on the line that starts with index. Commented Mar 28, 2024 at 3:36
  • Thanks, Ken. Fixed a few other things and that segment of the code now works.. Commented Mar 28, 2024 at 6:20
  • Following Update2 -- see code above, I received the following error ----Error message File "<ipython-input-29-0ee5224a45db>", line 7 print (df2) ^ SyntaxError: invalid syntax Commented Mar 28, 2024 at 6:53
  • The line before print(df2) has unbalanced parentheses. Commented Mar 28, 2024 at 9:58
  • Since Pandas is working, your installation here is not a problem, however, you'll have a better modern Jupyter experience going forward if you cease to use an exclamation point in conjunction with install commands. Specifically, it should be %pip install pandas. In 2019 the magic version of the install commands were added to insure the installations occur in the environment where the kernel backing the active notebook is running. The exclamation point doesn't do that and so can at times lead to issues. .... Commented Mar 28, 2024 at 12:24

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.