Python Pandas ValueError Arrays Must be All Same Length

前端 未结 5 1234
终归单人心
终归单人心 2020-12-14 02:15

Iterates over a big list of .mp3 links to get the metadata tags and save it to an Excel file. Results in this error. I appreciate any help. Thanks.

    #pri         


        
相关标签:
5条回答
  • 2020-12-14 02:51

    You can pad the shortest lists with empty elements:

    def pad_dict_list(dict_list, padel):
        lmax = 0
        for lname in dict_list.keys():
            lmax = max(lmax, len(dict_list[lname]))
        for lname in dict_list.keys():
            ll = len(dict_list[lname])
            if  ll < lmax:
                dict_list[lname] += [padel] * (lmax - ll)
        return dict_list
    
    0 讨论(0)
  • 2020-12-14 02:57

    you can do this to avoid that error

    a = {'Links' : lines ,'Titles' : titles , 'Singers': finalsingers , 'Albums':finalalbums , 'Years' : years}
    df = pd.DataFrame.from_dict(a, orient='index')
    df = df.transpose()
    
    0 讨论(0)
  • 2020-12-14 03:02

    Duplicate variable names caused this problem for me

    0 讨论(0)
  • 2020-12-14 03:08

    It's telling you that the arrays (lines, titles, finalsingers, etc...) are not of the same length. You can test this by

    print(len(lines), len(titles), len(finalsingers)) # Print all of them out here
    

    This will show you which data is malformed and then you'll need to do some investigating into what the right way to correct this is.

    0 讨论(0)
  • 2020-12-14 03:16

    I have come across the same error while reading JSON file to the pandas frame. adding linesbool, default False parameter solved the issue.

    StringData = StringIO(obj.get()['Body'].read().decode('utf-8'))
                    mydata = pdf.read_json(StringData, lines=True)
    
    0 讨论(0)
提交回复
热议问题