pandas-dev / pandas

Flexible and powerful data analysis / manipulation library for Python, providing labeled data structures similar to R data.frame objects, statistical functions, and much more
https://pandas.pydata.org
BSD 3-Clause "New" or "Revised" License
43.76k stars 17.96k forks source link

Create to_elastic method #28895

Closed kDmartel closed 5 years ago

kDmartel commented 5 years ago

Code Sample, a copy-pastable example if possible

Problem description

Create method to export a pandas dataframe data to elasticsearch json format like to_excel, to_csv, to_sql methods.

Input

df : pandas dataframe index : str : elasticsearch index type : str : elasticsearch type EX : df.head() Name Age Weight 0 Kevin 26 94 1 Marc 32 70 2 Louis 35 80

index = 'personnes'

type = 'homme'

Usage

df.to_elastic(file_path, 'index'=index, 'type'=type)

Expected Output

{"index":{"_index": "personnes","_type":"homme","_id":1}} {"fields" : {"Name" : "Kevin","Age" : 26,"Weight" : 94} {"index" :{"_index": "personnes","_type":"homme","_id":2}} {"fields" : {"Name" : "Marx","Age" : 32,"Weight" : 70} {"index" :{"_index": "personnes","_type":"homme","_id":3}} {"fields" : {"Name" : "Louis","Age" : 35,"Weight" : 80}

mroeschke commented 5 years ago

Duplicate discussion in https://github.com/pandas-dev/pandas/issues/23315