के साथ कॉलम की गलत संख्या की अपेक्षा करता है मेरे पास एक सीएसवी फ़ाइल है जिसमें कुछ सौ पंक्तियां और 26 कॉलम हैं, लेकिन अंतिम कुछ स्तंभों में केवल कुछ पंक्तियों में एक मान है और वे बीच की ओर हैं या वे फ़ाइल का अंत जब मैं read_csv() का उपयोग करने में इसे पढ़ने की कोशिश करता हूं तो मुझे निम्न त्रुटि मिलती है। "ValueError: 23 कॉलम की अपेक्षा, पंक्ति 64 में 26 मिली"पांडस read_csv रैग किए गए सीएसवी फ़ाइल
मैं नहीं देख सकता कि फाइल में कॉलम की संख्या स्पष्ट रूप से कहां से बताती है, या यह निर्धारित करता है कि फाइल को कितने कॉलम के बारे में सोचना चाहिए। डंप नीचे
In [3]:
infile =open(easygui.fileopenbox(),"r")
pledge = read_csv(infile,parse_dates='true')
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-3-b35e7a16b389> in <module>()
1 infile =open(easygui.fileopenbox(),"r")
2
----> 3 pledge = read_csv(infile,parse_dates='true')
C:\Python27\lib\site-packages\pandas-0.8.1-py2.7-win32.egg\pandas\io\parsers.pyc in read_csv(filepath_or_buffer, sep, dialect, header, index_col, names, skiprows, na_values, thousands, comment, parse_dates, keep_date_col, dayfirst, date_parser, nrows, iterator, chunksize, skip_footer, converters, verbose, delimiter, encoding, squeeze)
234 kwds['delimiter'] = sep
235
--> 236 return _read(TextParser, filepath_or_buffer, kwds)
237
238 @Appender(_read_table_doc)
C:\Python27\lib\site-packages\pandas-0.8.1-py2.7-win32.egg\pandas\io\parsers.pyc in _read(cls, filepath_or_buffer, kwds)
189 return parser
190
--> 191 return parser.get_chunk()
192
193 @Appender(_read_csv_doc)
C:\Python27\lib\site-packages\pandas-0.8.1-py2.7-win32.egg\pandas\io\parsers.pyc in get_chunk(self, rows)
779 msg = ('Expecting %d columns, got %d in row %d' %
780 (col_len, zip_len, row_num))
--> 781 raise ValueError(msg)
782
783 data = dict((k, v) for k, v in izip(self.columns, zipped_content))
ValueError: Expecting 23 columns, got 26 in row 64
धन्यवाद रोमन, मैं यह समझने के बीच में था कि इसे और अधिक पठनीय बनाने के लिए और आप मुझे इसे हराते हैं। :) – chrisfs
एनपी, आपके प्रश्न के बारे में, क्या आपके पास अपनी फ़ाइल में हेडर है? –
नहीं, कोई हेडर नहीं, ऐसा लगता है या नीचे दिया गया उत्तर जाने का तरीका होगा। – chrisfs