2016-11-05 1 views
3

큰 목록의 .mp3 링크를 반복하여 메타 데이터 태그를 가져 와서 Excel 파일에 저장하십시오. 이 오류가 발생합니다. 어떤 도움을 주셔서 감사합니다. 감사.Python Pandas ValueError 배열은 모두 같아야합니다.

#print is_connected(); 

    # Create a Pandas dataframe from the data. 
df = pd.DataFrame({'Links' : lines ,'Titles' : titles , 'Singers': finalsingers , 'Albums':finalalbums , 'Years' : years}) 


    # Create a Pandas Excel writer using XlsxWriter as the engine. 
writer = pd.ExcelWriter(xlspath, engine='xlsxwriter') 

    # Convert the dataframe to an XlsxWriter Excel object. 
df.to_excel(writer, sheet_name='Sheet1') 
    #df.to_excel(writer, sheet_name='Sheet1') 


    # Close the Pandas Excel writer and output the Excel file. 
writer.save() 

Traceback (most recent call last): 
    File "mp.py", line 87, in <module> 
    df = pd.DataFrame({'Links' : lines ,'Titles' : titles , 'Singers': finalsingers , 'Albums':finalalbums , 'Years' : years}) 
    File "C:\Python27\lib\site-packages\pandas\core\frame.py", line 266, in __init__ 
    mgr = self._init_dict(data, index, columns, dtype=dtype) 
    File "C:\Python27\lib\site-packages\pandas\core\frame.py", line 402, in _init_dict 
    return _arrays_to_mgr(arrays, data_names, index, columns, dtype=dtype) 
    File "C:\Python27\lib\site-packages\pandas\core\frame.py", line 5409, in _arrays_to_mgr 
    index = extract_index(arrays) 
    File "C:\Python27\lib\site-packages\pandas\core\frame.py", line 5457, in extract_index 
    raise ValueError('arrays must all be same length') 
ValueError: arrays must all be same length 

답변

2

배열 (선, 제목, 최종선 등 ...)의 길이가 같지 않다는 것을 알려줍니다. 당신은이 형식이 잘못되는 데이터를 표시합니다

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

하여이를 테스트 할 수 있습니다 그리고 당신은이 문제를 해결하는 올바른 방법이 무엇인지에 몇 가지 조사를 수행해야합니다.

6

해당 오류이의

a = {'Links' : lines ,'Titles' : titles , 'Singers': finalsingers , 'Albums':finalalbums , 'Years' : years} 
df = pd.DataFrame.from_dict(a, orient='index') 
df.transpose() 
+0

가능한 중복 http://stackoverflow.com/questions/19736080/creating-dataframe-from-a-dictionary-where-entries-have-을 방지하기 위해이 작업을 수행 할 수 있습니다 다른 길이 –