question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pandas DataFrame groupby().Size() giving 'Value Error : Length of passed values is 65, index implies 0'

See original GitHub issue

Code Sample, a copy-pastable example if possible

from os import path
import pandas as pd
import numpy as np

input_file = path.join(r'C:\DUMP', 'Process Log 2 Week_2.txt')
tdf = pd.read_csv(input_file, low_memory=False)

# Value Error in this statement -->
tdf_gsdf = tdvdf.groupby(tdvdf.columns.tolist()).size() 

Problem description

The Above code is giving ‘Value Error : Length of passed values is 65, index implies 0’ I’m trying to identify unique/duplicate rows by grouping by all of the columns in Data Frame.

(Attached the text file here). Process Log 2 Week_2.txt

I’m new to Python, Pandas and this community as well. just trying to automate few tasks in my project. I think this might be related to Issue #21624. Not sure how to link.

Expected Output

Output should give distinct rows and corresponding count from DataFrame.

Output of pd.show_versions()

[paste the output of pd.show_versions() here below this line] INSTALLED VERSIONS

commit: None python: 3.6.6.final.0 python-bits: 64 OS: Windows OS-release: 7 machine: AMD64 processor: Intel64 Family 6 Model 63 Stepping 2, GenuineIntel byteorder: little LC_ALL: None LANG: None LOCALE: None.None

pandas: 0.23.4 pytest: 3.8.0 pip: 10.0.1 setuptools: 40.4.3 Cython: 0.28.5 numpy: 1.15.1 scipy: 1.1.0 pyarrow: None xarray: None IPython: 6.5.0 sphinx: 1.8.1 patsy: 0.5.0 dateutil: 2.7.3 pytz: 2018.5 blosc: None bottleneck: 1.2.1 tables: 3.4.4 numexpr: 2.6.8 feather: None matplotlib: 2.2.3 openpyxl: 2.5.8 xlrd: 1.1.0 xlwt: 1.3.0 xlsxwriter: 1.1.1 lxml: 4.2.5 bs4: 4.6.3 html5lib: 1.0.1 sqlalchemy: 1.2.11 pymysql: None psycopg2: None jinja2: 2.10 s3fs: None fastparquet: None pandas_gbq: None pandas_datareader: None

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
math-and-datacommented, Oct 8, 2018

The problem are the NA entries in your dataset. Each row in your dataset has at least one NA somewhere. When you apply .groupby to NA entries, it wouldn’t know how to group NAs so it removes them, leaving an empty result (length 0).

See http://pandas.pydata.org/pandas-docs/stable/missing_data.html#na-values-in-groupby and http://pandas.pydata.org/pandas-docs/stable/groupby.html#na-and-nat-group-handling

0reactions
H-peacecommented, Aug 18, 2019

look here,this Error:help me Error

Read more comments on GitHub >

github_iconTop Results From Across the Web

ValueError: Length of passed values is 7, index implies 0
I know that the index is 7 because there are 7 values in the OHLCcolumns that I am getting into the dataframe. I...
Read more >
How to Fix: Length of values does not match length of index
In this article we will fix the error: The length of values does not match the length of the index in Python.
Read more >
Python error – Length of passed values is 6, index implies 2 ...
ValueError : Length of passed values is 6, index implies 2. Let's create a sample Pandas DataFrame for our demo purpose: ...
Read more >
ValueError: Length of passed values is 0, index implies 11?
Coding example for the question ValueError: Length of passed values is 0, index implies 11?-Pandas,Python.
Read more >
Group by: split-apply-combine — pandas 1.5.2 documentation
On a DataFrame, we obtain a GroupBy object by calling groupby() . ... used as the group key in a groupby operation, all...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found