# Why client returns 2 dataframes?

**URL:** <https://community.influxdata.com/t/why-client-returns-2-dataframes/26094>\
**Category:** Systems\
**Tags:** influxdb-cloud-2-0, python\
**Created:** [August 11, 2022, 11:18am UTC](https://community.influxdata.com/t/why-client-returns-2-dataframes/26094 "2022-08-11T11:18:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![klyk](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/klyk/32/15715_2.png) [@klyk](https://community.influxdata.com/u/klyk)\
**Post date:** [August 11, 2022, 11:18am UTC](https://community.influxdata.com/t/why-client-returns-2-dataframes/26094/1 "2022-08-11T11:18:26Z")

</div>

The question is why a query returns multiple dataframes instead of one.  
Each dataframe contains several tables (`table` column`, where a term Table, as far as I see, is to group timeseries.  
Consider an example:

```python
import influxdb_client

bucket = "aaa"
org = "bbb"
token = "<my token from secrets>"
# Store the URL of your InfluxDB instance
url="https://us-west-2-2.aws.cloud2.influxdata.com/"

client = influxdb_client.InfluxDBClient(
   url=url,
   token=token,
   org=org
)

query_api = client.query_api()

query = """from(bucket: "<bucket>")
  |> range(start: -10m)
  |> filter(fn: (r) => r["_measurement"] == "xxx")
  |> filter(fn: (r) => r["_field"] == "mean_yyy")
  |> aggregateWindow(every: 5m, fn: mean, createEmpty: false)
  |> yield(name: "mean")
  |> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")"""
dataframes = query_api.query_data_frame(query)

```

What I get is two dataframes with the following columns:

```auto
Index(['result', 'table', '_start', '_stop', '_time', '_value', '_field',
       '_measurement', 'host_id'],
      dtype='object')
# and
Index(['result', 'table', '_start', '_stop', '_time', '_measurement',
       'host_id', 'mean_yyy'],
      dtype='object')

```

More than that, `_value` from the first dataframe seems to have the same values as `mean_yyy` from the second.

If I request 2 fields instead of one, this will generate 1400 dataframes. Looks really confusing

---

<div class="post-metadata">

**Author:** ![Anaisdg](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/anaisdg/32/6401_2.png) [@Anaisdg](https://community.influxdata.com/u/Anaisdg)\
**Post date:** [August 12, 2022, 6:08pm UTC](https://community.influxdata.com/t/why-client-returns-2-dataframes/26094/2 "2022-08-12T18:08:47Z")

</div>

Hello @klyk,  
You return a dataframe for each table stream result.  
You have one result with the name “\_mean” from the ` |> yield(name: "mean")` and a second one with the name “\_result” (default name) from the last line.  
Does that make sense? Comment out the yield() function and I believe you’ll have what you expect.

> **[TL;DR InfluxDB Tech Tips: Multiple Aggregations with yield() in Flux](https://www.influxdata.com/blog/tldr-influxdb-tech-tips-multiple-aggregations-yield-flux/)**
>
> Invoking multiple yield() functions allows you to return multiple table streams from a single Flux script simultaneously.

> **[yield() function | Flux 0.x Documentation](https://docs.influxdata.com/flux/v0.x/stdlib/universe/yield/)**
>
> yield() delivers input data as a result of the query.

---

<div class="post-metadata">

**Author:** ![klyk](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/klyk/32/15715_2.png) [@klyk](https://community.influxdata.com/u/klyk)\
**Post date:** [August 16, 2022, 9:25am UTC](https://community.influxdata.com/t/why-client-returns-2-dataframes/26094/3 "2022-08-16T09:25:33Z")

</div>

Kind of a bit clearer now, but why does it emits 1400 dataframes if I specify something like `|> filter(fn: (r) => r["_field"] == "mean_yyy" o r["_field"] == "mean_zzz")`? So I’ve added `or` for the field name for one of the filters

---

<div class="post-metadata">

**Author:** ![Anaisdg](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/anaisdg/32/6401_2.png) [@Anaisdg](https://community.influxdata.com/u/Anaisdg)\
**Post date:** [August 16, 2022, 5:25pm UTC](https://community.influxdata.com/t/why-client-returns-2-dataframes/26094/4 "2022-08-16T17:25:46Z")

</div>

I believe each table in the stream returns a dataframe.  
You must have a ton of tags? How many tags do you have for those two fields?
