How can I import data from a Pandas DataFrame to airtable. I've been searching for hours now, havent seen anything. For example this is my dataframe:
ar = numpy.array([[1.1, 2, 3.3, 4], [2.7, 10, 5.4, 7], [5.3, 9, 1.5, 15]])
df = pandas.DataFrame(ar,columns = ['A', 'B', 'C', 'D'])
And it gives this:
A B C D
1.1 2 3.3 4
2.7 10 5.4 7
5.3 9 1.5 15
So how do I import this DataFrame into a table named "alpha" and DB named "test" in Airtable ? To have this data in my table.
Okay, i figured something out.It worked perfectly So i have this table presented like this:
id name surname age
1 Ekane Emile 21
2 Ekane Emile 21
I wrote the following code:
import pandas
import requests
#AUTHENTICATION
#Global variables
AIRTABLE_BASE_ID = 'BASE_ID'
AIRTABLE_API_KEY= 'API_KEY'
AIRTABLE_TABLE_NAME='TABLE_NAME'
endpoint = f'https://api.airtable.com/v0/{AIRTABLE_BASE_ID}/{AIRTABLE_TABLE_NAME}'
#Headers
headers= {
"Authorization": f"Bearer {AIRTABLE_API_KEY}",
"Content-Type":"application/json"
}
#Dataframe to json data conversion
df = {
"fields": {
"id": "1",
"name": "Ekane",
"surname": "Emile",
"age": "21",
}
}
df_to_json = df.to_json()
data = json.dumps(df_to_json)
#post request
r = requests.post(endpoint, data=data, headers=headers)
print(r.json())
print(r.status_code) #200 if it works
And it worked, hope it helps. Note: The "fields" object must be present
How can I import data from a Pandas DataFrame to airtable. I've been searching for hours now, havent seen anything. For example this is my dataframe:
ar = numpy.array([[1.1, 2, 3.3, 4], [2.7, 10, 5.4, 7], [5.3, 9, 1.5, 15]])
df = pandas.DataFrame(ar,columns = ['A', 'B', 'C', 'D'])
And it gives this:
A B C D
1.1 2 3.3 4
2.7 10 5.4 7
5.3 9 1.5 15
So how do I import this DataFrame into a table named "alpha" and DB named "test" in Airtable ? To have this data in my table.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.