admin管理员组

文章数量:1332889

I'm pretty new to this, especially working with APIs. I am working with an API response from a postgres database. When I get the data back, it has a "data=" attached to the front like this:

data=[{'faculty_id': 2, 'first_name': 'Erin',....

I'm trying to place the data into a pandas dataframe, but having that extra bit at the front isn't helping. Any way I can strip off that first bit?

Current code:

response = supabase.table("faculty").select("*").execute()
# print(response)
df1 = pd.DataFrame(response)
df1

What I'm getting back:

    0   1
0   data    [{'faculty_id': 2, 'first_name': 'Erin', 'last...
1   count   None
2   __orig_class__  postgrest.base_request_builder.APIResponse[~_R...

I'm pretty new to this, especially working with APIs. I am working with an API response from a postgres database. When I get the data back, it has a "data=" attached to the front like this:

data=[{'faculty_id': 2, 'first_name': 'Erin',....

I'm trying to place the data into a pandas dataframe, but having that extra bit at the front isn't helping. Any way I can strip off that first bit?

Current code:

response = supabase.table("faculty").select("*").execute()
# print(response)
df1 = pd.DataFrame(response)
df1

What I'm getting back:

    0   1
0   data    [{'faculty_id': 2, 'first_name': 'Erin', 'last...
1   count   None
2   __orig_class__  postgrest.base_request_builder.APIResponse[~_R...
Share Improve this question edited Nov 21, 2024 at 2:51 Julien 15.2k6 gold badges33 silver badges58 bronze badges asked Nov 21, 2024 at 2:46 Alex SchiffAlex Schiff 131 bronze badge 2
  • Is that a string? Then just read a tutorial on string manipulation... otherwise we need more clarity. How to Ask and minimal reproducible example – Julien Commented Nov 21, 2024 at 2:53
  • @Julien It turns out its another object called APIResponse – Anubhav Sharma Commented Nov 21, 2024 at 3:14
Add a comment  | 

1 Answer 1

Reset to default 1

Use like this:

response = supabase.table("faculty").select("*").execute()
df1 = pd.DataFrame(response[5:])
df1

or

response = supabase.table("faculty").select("*").execute()
df1 = pd.DataFrame(response.data)
df1

本文标签: pythonHow do I remove the quotdataquot from an API responseStack Overflow