Home > Back-end >  Missing 1 required position argument: 'self'
Missing 1 required position argument: 'self'

Time:10-31

I'm having an issue with this: I'm getting the error "

bar() missing 1 required positional argument: 'self'

" I've tried fiddling this classes (using them and not using them) and with the self variable but I've got nothing. The function bar() comes from the pandas library I've imported as well as the dataframe (df) object. I've attached the main function of my code and the function in which the error is occurring.

def createDataframe(assessments):
    df = pd.DataFrame
    for review in assessments:   
        for skills in review.skillList:
            for skill in skills:
                tmp = pd.DataFrame({str(skill[:2]): [skill[3:]]})
                df.merge(tmp, how = 'right', right=tmp)
    return df

def plotData(df):
    ax = df.plot.bar(x='1.')
    plt.show()

def main():
    # Ensure proper CMD Line Arg
    if len(sys.argv) > 3:
        print("Error!")
        return 1
    assessments = dataParse()
    df = createDataframe(assessments)
    plotData(df)

Any help is welcome! Let me know!

EDIT: as tdy said in a comment below. I needed to add Parentheses to create an instance. Now I get no errors but I am left with nothing when printing df and nothing shows when plotting the information

CodePudding user response:

As mentioned here bar is a method for DataFrame instances So problem seems to in your createDataframe function, maybe you can post that too for further debugging. I am not sure what your data looks like but here is source for you to craete DataFrames for different options

CodePudding user response:

Pandas data frame do not have an option for in-place merge. In your code when you merge df, then assign it back to df like so:

 df = df.merge(tmp, how=‘right’, right=tmp)
  • Related