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

Implement DataFrame.idxmin and DataFrame.idxmax #352

Closed
V1NAY8 opened this issue Jun 4, 2021 · 3 comments
Closed

Implement DataFrame.idxmin and DataFrame.idxmax #352

V1NAY8 opened this issue Jun 4, 2021 · 3 comments

Comments

@V1NAY8
Copy link
Contributor

V1NAY8 commented Jun 4, 2021

I am thinking this should be implementable.

Reference for pandas idxmin: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.idxmin.html
Reference for pandas idxmax: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.idxmax.html

@V1NAY8
Copy link
Contributor Author

V1NAY8 commented Jun 7, 2021

I'll do this.

This can be broken into two:
for axis = "index" and axis = "columns"

@V1NAY8
Copy link
Contributor Author

V1NAY8 commented Jun 7, 2021

For index the following can be done. To match output with pandas

This can be achievable using top hits aggregation,
Input Query:

curl -X GET "localhost:9200/flights/_search?pretty" -H 'Content-Type: application/json' -d'
{
    "size": 0,
    "aggs": {
        "top_AvgTicketPrice": {
            "top_hits": {
                "sort": [
                    {
                        "AvgTicketPrice": {
                            "order": "desc"
                        }
                    }
                ],
                "_source": {
                    "includes": [
                        "_id",
                        "AvgTicketPrice"
                    ]
                },
                "size": 1
            }
        },
        "top_FlightDelayMin": {
            "top_hits": {
                "sort": [
                    {
                        "FlightDelayMin": {
                            "order": "desc"
                        }
                    }
                ],
                "_source": {
                    "includes": [
                        "_id",
                        "FlightDelayMin"
                    ]
                },
                "size": 1
            }
        },
        "top_dayOfWeek": {
            "top_hits": {
                "sort": [
                    {
                        "dayOfWeek": {
                            "order": "desc"
                        }
                    }
                ],
                "_source": {
                    "includes": [
                        "_id",
                        "dayOfWeek"
                    ]
                },
                "size": 1
            }
        }
    }
}
'

Output:

{
  "took" : 13,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 10000,
      "relation" : "gte"
    },
    "max_score" : null,
    "hits" : [ ]
  },
  "aggregations" : {
    "top_dayOfWeek" : {
      "hits" : {
        "total" : {
          "value" : 13059,
          "relation" : "eq"
        },
        "max_score" : null,
        "hits" : [
          {
            "_index" : "flights",
            "_type" : "_doc",
            "_id" : "1988",
            "_score" : null,
            "_source" : {
              "dayOfWeek" : 6
            },
            "sort" : [
              6
            ]
          }
        ]
      }
    },
    "top_AvgTicketPrice" : {
      "hits" : {
        "total" : {
          "value" : 13059,
          "relation" : "eq"
        },
        "max_score" : null,
        "hits" : [
          {
            "_index" : "flights",
            "_type" : "_doc",
            "_id" : "1843",
            "_score" : null,
            "_source" : {
              "AvgTicketPrice" : 1199.7290528077556
            },
            "sort" : [
              1199.729
            ]
          }
        ]
      }
    },
    "top_FlightDelayMin" : {
      "hits" : {
        "total" : {
          "value" : 13059,
          "relation" : "eq"
        },
        "max_score" : null,
        "hits" : [
          {
            "_index" : "flights",
            "_type" : "_doc",
            "_id" : "109",
            "_score" : null,
            "_source" : {
              "FlightDelayMin" : 360
            },
            "sort" : [
              360
            ]
          }
        ]
      }
    }
  }
}

@sethmlarson
Copy link
Contributor

Closed in #353

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