gtalarico / pyairtable

Python Api Client for Airtable
https://pyairtable.readthedocs.io
MIT License
783 stars 138 forks source link

Porting to pandas df #51

Closed getmykhan closed 4 years ago

getmykhan commented 5 years ago

Would you guys be interested in loading the data directly into pandas and then pushing it out back to Airtable

Thoughts?

JasonCrowe commented 5 years ago

I would be interested in functionality that would let me push a pandas dataframe to airtable. Especially if it handles the filetype conversions. :D

gtalarico commented 5 years ago

Do you already have something like that working outside the library? Curious how much code is required to add the feature.

getmykhan commented 5 years ago

Nope. Thinking of something along the lines of a strict JSON to bulk insert to airtables. Not sure if that is the most efficient way to do it though!

vlebert commented 5 years ago

Just a few tries if it can help. For reading :

from airtable import Airtable
import pandas as pd
airtable = Airtable( base key, table_name, api_key = 'XXXX')
record_list = airtable.get_all()
df = pd.DataFrame([record['fields'] for record in record_list])

Or with index as record ID

df = pd.DataFrame([record['fields'] for record in record_list], index = [record['id'] for record in record_list])

For writing a row from DataFrame :

record=df.iloc[i].to_dict()
airtable.batch_insert([record])

Of course handling missing data, links between table may be more complicated

gtalarico commented 4 years ago

we could add a snippet to doc on how to do this but won't add any pandas functionality to the lib