[Python] AttributeError: 'str' object has no attribute 'show' PySpark

Discussão em 'Python' iniciado por Stack, Fevereiro 10, 2025.

  1. Stack

    Stack Membro Participativo

    AttributeError: 'str' object has no attribute 'show'

    I am trying to pass any test json file as part of the command line argument. When doing so it treats it as a string , which I dont want but I want it to be treated as a DataFrame so it can show the dataframe with df.show(). I get this error message on the terminal saying AttributeError: 'str' object has no attribute 'show’.

    df = sqlContext.read.json(“tester.json")

    def show_data(df):
    df.show()

    parser = argparse.ArgumentParser()
    parser.add_argument(‘-I’, ‘—inputfile', required=True , default =df)
    args = parser.parse_args()
    show_data(args.parameterfile)

    Continue reading...

Compartilhe esta Página