# In results json, element\_count = 2047, however the total row count of CSV = 1003

**URL:** <https://discourse.greatexpectations.io/t/in-results-json-element-count-2047-however-the-total-row-count-of-csv-1003/2394>\
**Category:** GX Core Support\
**Created:** [September 17, 2026, 1:07am UTC](https://discourse.greatexpectations.io/t/in-results-json-element-count-2047-however-the-total-row-count-of-csv-1003/2394 "2026-09-17T01:07:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![KK1259](https://avatars.discourse-cdn.com/v4/letter/k/71c47a/32.png) [@KK1259](https://discourse.greatexpectations.io/u/KK1259)\
**Post date:** [September 17, 2026, 1:07am UTC](https://discourse.greatexpectations.io/t/in-results-json-element-count-2047-however-the-total-row-count-of-csv-1003/2394/1 "2026-09-17T01:07:21Z")

</div>

For expectation types:

1. expect\_column\_values\_to\_match\_regex

```
a. element_count = 2047

b. missing_count = 1044

```

2. expect\_column\_values\_to\_not\_be\_null

```
a. element_count = 2047

b. unexpected_count = 1064

```

3. expect\_column\_value\_lengths\_to\_be\_between

```
a. element_count = 2047

b. missing_count = 1044 

```

4. expect\_column\_values\_to\_be\_unique

```
a. element_count = 2047

b. missing_count = 1044

```

How exactly it is calculating that when there are only 1003 [1000 + 3] rows in my CSV with 3 of them being duplicate?

Where exactly the GX is getting 2047 / 1064 ?

---

<div class="post-metadata">

**Author:** ![joshstauffer](https://avatars.discourse-cdn.com/v4/letter/j/85e7bf/32.png) [@joshstauffer](https://discourse.greatexpectations.io/u/joshstauffer)\
**Post date:** [September 17, 2026, 5:58am UTC](https://discourse.greatexpectations.io/t/in-results-json-element-count-2047-however-the-total-row-count-of-csv-1003/2394/2 "2026-09-17T05:58:17Z")

</div>

Hi @KK1259, thanks for the question, I’d like to help you get to the bottom of this. As is, I don’t have enough information to understand what’s happening - could you share an example script that replicates this behavior? If that’s not possible, if you could share the code you use to setup GX and the general shape of your CSV I might be able to help.

---

<div class="post-metadata">

**Author:** ![KK1259](https://avatars.discourse-cdn.com/v4/letter/k/71c47a/32.png) [@KK1259](https://discourse.greatexpectations.io/u/KK1259)\
**Post date:** [September 17, 2026, 8:38pm UTC](https://discourse.greatexpectations.io/t/in-results-json-element-count-2047-however-the-total-row-count-of-csv-1003/2394/3 "2026-09-17T20:38:41Z")

</div>

Thank you @joshstauffer , following is the code snippet

# ============================

# General Config

# ============================

# Define output folder path under /kaggle/working/

output\_base\_path =

# Define Data-Source

source\_folder =

data\_source\_name = “gx\_sample\_data\_source”

# Scan all CSV files in source-folder & store their filenames in a dict [file: filename]

csv\_names = {}

for f in glob.glob(os.path.join(source\_folder, “\*.csv”)):

```
csv_names\[os.path.splitext(os.path.basename(f))\[0\]\] = os.path.basename(f)

```

# ============================

# GX Config

# ============================

# Define Context

context = gx.get\_context(mode=“file”, project\_root\_dir=output\_base\_path)

# Add the Data-Source to the Data Context

try:

```
data_source = context.data_sources.get(data_source_name)

```

except KeyError:

```
data_source = context.data_sources.add_pandas_filesystem(

                                                         name=data_source_name, 

                                                         base_directory=source_folder)

```

# Define Data Asset

assets = {}

for csv in csv\_names.keys():

```
dynamic_key = f"{csv}\_asset"

try:

    assets\[dynamic_key\] = data_source.add_csv_asset(name=dynamic_key)

except ValueError:

    assets\[dynamic_key\] = data_source.get_asset(dynamic_key)

```

# Verification

for k in assets.keys():

```
print(f"Asset {k} created.")

```

# ============================

# GX Batch Load

# ============================

# Retrieve Data Asset

bugs\_asset = assets[“BUGS\_asset”]

# Add Batch-Definition to Data Asset

batch\_definition\_name = “bugs\_data”

batch\_definition\_path = list(csv\_names.values())[0] # ← BUGS.csv

try:

```
batch_definition = bugs_asset.add_batch_definition_path(

    name=batch_definition_name, 

    path=batch_definition_path

)

```

except ValueError:

```
batch_definition = bugs_asset.get_batch_definition(batch_definition_name)

```

# Fetch batch

batch = batch\_definition.get\_batch()

batch.head()

# =====================================================

# Define Expectations (data validation business rules)

# =====================================================

“”"

EXPECTATION#1: Column = workitem\_type (type = Bug only)

-------------------------------------------------------------------------

Scope : Table-Specific (BUGS)

Business Rule : workitem\_type column must strictly contain ONLY ‘Bug’.

Target Column : workitem\_type

Validation : Value set = [‘Bug’]

Failure Impact: Critical - Unexpected workitem types present in dataset.

-------------------------------------------------------------------------

“”"

exp\_workitem\_type\_is\_bug = gx.expectations.ExpectColumnDistinctValuesToEqualSet(

```
column="workitem_type",

value_set=\["Bug"\]

```

)

“”"

EXPECTATION#2: Column = created\_by (only MOJ internal users)

-------------------------------------------------------------------------

Scope : Generic

Business Rule : created\_by must contain an email with a ‘@…justice’ domain.

Target Column : created\_by

Validation : Matches regex r"@.\*justice" (Case-insensitive)

Failure Impact: Warning — Invalid email format or non-justice domain detected.

-------------------------------------------------------------------------

“”"

exp\_created\_by\_justice\_domain = gx.expectations.ExpectColumnValuesToMatchRegex(

```
column="created_by",

regex=r"(?i)@.\*justice", # (?i) makes it case-insensitive

severity="warning"

```

)

“”"

EXPECTATION#3: Column = severity (non null)

-------------------------------------------------------------------------

Scope : Generic

Business Rule : severity must be non-null

Target Column : severity

Validation : values to be not null

Failure Impact: Critical - Null/blank present in severity column

-------------------------------------------------------------------------

“”"

exp\_severity\_notnull = gx.expectations.ExpectColumnValuesToNotBeNull(

```
column="severity"

```

)

“”"

EXPECTATION#4: Column = id (value length between 4 & 6)

-------------------------------------------------------------------------

Scope : Generic

Business Rule : id value length must be between 4 & 6

Target Column : id

Validation : min\_value = 5 & max\_value = 9

Failure Impact: Warning - Unknown Id values in the dataset

-------------------------------------------------------------------------

“”"

exp\_id\_length = gx.expectations.ExpectColumnValueLengthsToBeBetween(

```
column="id",

min_value=5,

max_value=9,

severity="warning"

```

)

“”"

EXPECTATION#5: Column = id (duplicate check)

-------------------------------------------------------------------------

Scope : Generic

Business Rule : primary key (id) should be unique

Target Column : id

Validation : no duplicates

Failure Impact: Critical

-------------------------------------------------------------------------

“”"

exp\_unique\_id = gx.expectations.ExpectColumnValuesToBeUnique(

```
column="id"

```

)

# Expectations List

expectations\_list = [

```
exp_workitem_type_is_bug, # <- workitemtype must be Bug

exp_created_by_justice_domain, # <- created_by email domain must be "justice" 

exp_severity_notnull, # <- severity must non null 

exp_id_length, # <- id length must be between 4 & 6

exp_unique_id # <- id must be unique 

```

]

# ============================

# Expectation Suite

# ============================

# Define a Base Expectation Suite

suite\_name = “base\_expectation\_suite”

# Add suite to the context

try:

```
suite = context.suites.add(gx.ExpectationSuite(name=suite_name))

```

except gx.exceptions.DataContextError:

```
suite = context.suites.get(name=suite_name)

```

# Add Expectations to Suite

for exp in expectations\_list:

```
suite.add_expectation(exp)

```

# Verification

print(f"Total expectations added: {len(suite.expectations)}")

# ============================

# Validation Definition

# ============================

# Define unique validation definition name

val\_definition\_name = “bugs\_validation\_definition”

# Define validation definition & add to context

try:

```
validation_definition = context.validation_definitions.add(

    gx.ValidationDefinition(

        data=batch_definition,

        suite=suite,

        name=val_definition_name,

    )

)

```

except (gx.exceptions.DataContextError, ValueError):

```
validation_definition = context.validation_definitions.get(

    name=val_definition_name

)

```

# ============================

# Run Validation Definition

# ============================

# Execute the validation run

validation\_results = validation\_definition.run()

# Check overall pass/fail status

print(f"Validation Result: {validation\_results}")

---

<div class="post-metadata">

**Author:** ![joshstauffer](https://avatars.discourse-cdn.com/v4/letter/j/85e7bf/32.png) [@joshstauffer](https://discourse.greatexpectations.io/u/joshstauffer)\
**Post date:** [September 21, 2026, 6:42am UTC](https://discourse.greatexpectations.io/t/in-results-json-element-count-2047-however-the-total-row-count-of-csv-1003/2394/4 "2026-09-21T06:42:53Z")

</div>

Thanks for the detailed response @KK1259! The value that GX reports for `element_count` is the row count Pandas reports for a given CSV, so my first guess is that there are 1044 empty lines at the end of the file `,,,,,` that are all-null. You could verify that directly with Pandas:

```auto
import pandas as pd
df = pd.read_csv("<source_founder>/BUGS.csv")
print(len(df), df["id"].isna()].head()) # expected: 2047 and 1044

```

---

<div class="post-metadata">

**Author:** ![KK1259](https://avatars.discourse-cdn.com/v4/letter/k/71c47a/32.png) [@KK1259](https://discourse.greatexpectations.io/u/KK1259)\
**Post date:** [September 21, 2026, 9:56pm UTC](https://discourse.greatexpectations.io/t/in-results-json-element-count-2047-however-the-total-row-count-of-csv-1003/2394/5 "2026-09-21T21:56:39Z")

</div>

Thank you @joshstauffer , the issue was with one of the column which had data like , . So the pandas (read\_csv) was reading extra values.
