concrete_NLP_tutorial icon indicating copy to clipboard operation
concrete_NLP_tutorial copied to clipboard

ValueError:Length mismatch: Expected axis has 13 elements, new values have 3 elements

Open vikash512 opened this issue 6 years ago • 1 comments

import keras import nltk import pandas as pd import numpy as np import re import codecs

input_file = codecs.open("/home/vikash/gen/social_media-disaster-tweets-DFE.csv", 'r' , encoding='utf-8', errors='replace') print input_file output_file = open("social_media_relevant_cols_clean.csv", "w")

def sanitize_characters(raw, clean): print("enter the function") for line in input_file: output_file.write(line)

sanitize_characters(input_file, output_file) questions = pd.read_csv("social_media_relevant_cols_clean.csv") questions.columns = ('text', 'choose_one', 'choose_label') questions.head() questions.tail()

The following is the error

Traceback (most recent call last): File "/home/vikash/gen/concept.py", line 22, in questions.columns = ('text', 'choose_one', 'choose_label') File "/home/vikash/.local/lib/python2.7/site-packages/pandas/core/generic.py", line 4385, in setattr return object.setattr(self, name, value) File "pandas/_libs/properties.pyx", line 69, in pandas._libs.properties.AxisProperty.set File "/home/vikash/.local/lib/python2.7/site-packages/pandas/core/generic.py", line 645, in _set_axis self._data.set_axis(axis, labels) File "/home/vikash/.local/lib/python2.7/site-packages/pandas/core/internals.py", line 3323, in set_axis 'values have {new} elements'.format(old=old_len, new=new_len)) ValueError: Length mismatch: Expected axis has 13 elements, new values have 3 elements

vikash512 avatar May 31 '18 05:05 vikash512

@vikash512 I hope you found an answer, but I try to describe this situation. Here is a description what can you do with DataFrame. You can try to delete unnecessary columns, but also you can select some of them by using operation like this questions.head()[["text", "choose_one"]] questions[["text", "choose_one"]].describe()

137x3w avatar Dec 09 '18 21:12 137x3w