Loading Pandas Dataframes into Glue-Jupyter.

14 views
Skip to first unread message

Doug Redden

unread,
Jan 29, 2020, 12:22:42 PM1/29/20
to Glue users

Hi,

This is similar to a recent question about loading Pandas Dataframes but instead of Glue .... it is for Glue-Jupyter.

I have been loading data from csv files and this works well.   I would now like to load pandas dataframes into Glue-Jupyter.  Please could you give me some advice.  See some of my attempts below


from glue_jupyter.data import require_data
import glue_jupyter as gj
import numpy as np

require_data('Planes/boston_planes_6h.csv')

app = gj.jglue()
planesFromCSV = app.load_data('boston_planes_6h.csv')

df = planes.to_dataframe()
df = df.dropna(how='all', axis=1)  # remove columns with Nans  
df = df.select_dtypes([np.number])  # remove non-numeric columns  
df

# This works well
scatter_viewer = app.scatter2d(x=df.columns[3], y=df.columns[4], data=planesFromCSV)  

# Loading in a dataframe doesn't work
app2 = gj.jglue()
planes_From_df = app2.load_data(df) # KeyError: "Don't know how to open file: 
# planes_From_df = app2.add_data(df)   # KeyError: "Don't know how to open file: 

scatter_viewer = app2.scatter2d(x=df.columns[3], y=df.columns[4], data=planes_From_df, show=False)


Thanks,

Doug

phed...@gmail.com

unread,
Jan 29, 2020, 12:33:26 PM1/29/20
to glue...@googlegroups.com

I was only able to load pandas by first saving them as csv files

--
You received this message because you are subscribed to the Google Groups "Glue users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to glue-viz+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/glue-viz/7f7d10e9-ff0e-4551-9332-c100137a94bd%40googlegroups.com.

Doug Redden

unread,
Jan 30, 2020, 5:24:39 AM1/30/20
to Glue users
I've worked it out!  Its quite simple.   See below.

# ------------
from glue_jupyter.data import require_data
import glue_jupyter as gj
import numpy as np

require_data('Planes/boston_planes_6h.csv')

app = gj.jglue()
planesFromCSV = app.load_data('boston_planes_6h.csv')

df = planesFromCSV.to_dataframe()
df = df.dropna(how='all', axis=1)  # remove columns with Nans  
df = df.select_dtypes([np.number])  # remove non-numeric columns  
df

scatter_viewer = app.scatter2d(x=df.columns[3], y=df.columns[4], data=planesFromCSV)  

# Loading in a dataframe doesn't work
app2 = gj.jglue(data=df)

scatter_viewer = app2.scatter2d(x=df.columns[3], y=df.columns[4])



To unsubscribe from this group and stop receiving emails from it, send an email to glue...@googlegroups.com.

Thomas Robitaille

unread,
Feb 9, 2020, 10:40:13 AM2/9/20
to glue...@googlegroups.com
Hi Doug,

An alternative solution is to use app.add_data's ability to understand dataframes:

import pandas
df = pandas.read_csv('boston_planes_6h.csv')
planes = app.add_data(planes=df)[0]

After this you can use 'planes' as a regular glue dataset, e.g:

scatter_viewer = app.scatter2d(x='x', y='y', data=planes)

Let me know if this doesn't work!

Cheers,
Tom


To unsubscribe from this group and stop receiving emails from it, send an email to glue-viz+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/glue-viz/d4a98cd1-6bc0-42c0-ba94-de3890a9d1a9%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages