Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
vikash512 opened this issue May 31, 2018 · 1 comment

Comments

@vikash512
Copy link

vikash512 commented May 31, 2018

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

@137x3w
Copy link

137x3w commented Dec 9, 2018

@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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants