NodesTable API Reference¶
Type: groggy.NodesTable
Overview¶
Tabular view of node data with columns for node attributes.
Primary Use Cases: - Analyzing node attributes in tabular form - Aggregating node data - Exporting node information
Related Objects:
- GraphTable
- BaseTable
- NodesAccessor
Complete Method Reference¶
The following methods are available on NodesTable objects. This reference is generated from comprehensive API testing and shows all empirically validated methods.
| Method | Returns | Status |
|---|---|---|
base_table() |
BaseTable |
✓ |
drop_columns() |
NodesTable |
✓ |
filter() |
? |
✗ |
filter_by_attr() |
? |
✗ |
from_csv() |
? |
✗ |
from_dict() |
? |
✗ |
from_json() |
? |
✗ |
from_parquet() |
? |
✗ |
group_by() |
NodesTableArray |
✓ |
head() |
NodesTable |
✓ |
interactive() |
str |
✓ |
interactive_embed() |
str |
✓ |
interactive_viz() |
VizAccessor |
✓ |
into_base_table() |
BaseTable |
✓ |
is_empty() |
bool |
✓ |
iter() |
NodesTableRowIterator |
✓ |
ncols() |
int |
✓ |
node_ids() |
NumArray |
✓ |
nrows() |
int |
✓ |
rich_display() |
str |
✓ |
select() |
NodesTable |
✓ |
shape() |
tuple |
✓ |
slice() |
? |
✗ |
sort_by() |
NodesTable |
✓ |
sort_values() |
NodesTable |
✓ |
tail() |
NodesTable |
✓ |
to_csv() |
? |
✗ |
to_json() |
? |
✗ |
to_pandas() |
DataFrame |
✓ |
to_parquet() |
? |
✗ |
unique_attr_values() |
? |
✗ |
viz() |
VizAccessor |
✓ |
with_attributes() |
? |
✗ |
Legend:
- ✓ = Method tested and working
- ✗ = Method failed in testing or not yet validated
- ? = Return type not yet determined
Detailed Method Reference¶
Creating NodesTable¶
NodesTable is accessed from GraphTable or directly from graph/subgraph:
import groggy as gr
g = gr.generators.karate_club()
# From graph
nodes_table = g.nodes.table()
# From GraphTable
table = g.table()
nodes_table = table.nodes
# From subgraph
young = g.nodes[g.nodes["age"] < 30]
young_nodes = young.table().nodes
Core Methods¶
node_ids()¶
Get array of node IDs.
Returns:
- NumArray: Node IDs
Example:
shape()¶
Get table dimensions.
Returns:
- tuple[int, int]: (rows, columns)
Example:
nodes_table = g.nodes.table()
rows, cols = nodes_table.shape()
print(f"{rows} nodes, {cols} attributes")
nrows() / ncols()¶
Get number of rows or columns.
Returns:
- int: Row or column count
Example:
is_empty()¶
Check if table is empty.
Returns:
- bool: True if no rows
Example:
Display & Inspection¶
head(n=5) / tail(n=5)¶
Show first/last n rows.
Returns:
- NodesTable: Subset table
Example:
iter()¶
Iterate over rows.
Returns: - Iterator over rows
Example:
Selection & Filtering¶
select(columns)¶
Select specific columns.
Parameters:
- columns (list[str]): Column names to keep
Returns:
- NodesTable: Table with selected columns
Example:
drop_columns(columns)¶
Remove specific columns.
Parameters:
- columns (list[str]): Columns to drop
Returns:
- NodesTable: Table without specified columns
Example:
Sorting¶
sort_by(column) / sort_values(column)¶
Sort by column values.
Parameters:
- column (str): Column name to sort by
Returns:
- NodesTable: Sorted table
Example:
# Sort by age
by_age = nodes_table.sort_by("age")
print(by_age.head())
# Descending (if supported)
# by_age_desc = nodes_table.sort_by("age", ascending=False)
Notes: Both methods are aliases
Grouping¶
group_by(column)¶
Group rows by column value.
Parameters:
- column (str): Column to group by
Returns:
- NodesTableArray: Array of grouped tables
Example:
# Group by city
by_city = nodes_table.group_by("city")
for city_table in by_city:
print(f"City: {city_table.nrows()} nodes")
Export¶
to_pandas()¶
Convert to pandas DataFrame.
Returns:
- pandas.DataFrame: DataFrame
Example:
to_csv(path) / to_parquet(path) / to_json(path)¶
Export to file formats.
Parameters:
- path (str): File path
Example:
nodes_table.to_csv("nodes.csv")
nodes_table.to_parquet("nodes.parquet")
nodes_table.to_json("nodes.json")
Conversion¶
base_table() / into_base_table()¶
Convert to BaseTable.
Returns:
- BaseTable: Generic table
Example:
Notes: Both methods are aliases
Usage Patterns¶
Pattern 1: Basic Export¶
nodes_table = g.nodes.table()
# To pandas
df = nodes_table.to_pandas()
print(df.info())
# To CSV
nodes_table.to_csv("nodes.csv", index=False)
Pattern 2: Column Selection¶
# Select specific attributes
subset = nodes_table.select(["id", "name", "age"])
# Export subset
subset.to_csv("nodes_basic.csv")
Pattern 3: Sorting & Display¶
# Sort by attribute
by_age = nodes_table.sort_by("age")
# Show oldest/youngest
print("Youngest:")
by_age.head(5)
print("\nOldest:")
by_age.tail(5)
Pattern 4: Grouping Analysis¶
# Group by category
by_dept = nodes_table.group_by("department")
# Analyze each group
for dept_table in by_dept:
df = dept_table.to_pandas()
print(f"Dept size: {len(df)}")
print(f"Avg age: {df['age'].mean():.1f}")
Quick Reference¶
| Method | Returns | Description |
|---|---|---|
node_ids() |
NumArray |
Get node IDs |
shape() |
tuple |
(rows, cols) |
nrows() |
int |
Number of rows |
ncols() |
int |
Number of columns |
head(n) |
NodesTable |
First n rows |
tail(n) |
NodesTable |
Last n rows |
select(cols) |
NodesTable |
Select columns |
drop_columns(cols) |
NodesTable |
Remove columns |
sort_by(col) |
NodesTable |
Sort by column |
group_by(col) |
NodesTableArray |
Group by column |
to_pandas() |
DataFrame |
Export to pandas |
to_csv(path) |
None | Export to CSV |
See Also¶
- User Guide: Comprehensive tutorial and patterns
- GraphTable API: Parent container table
- EdgesTable API: Edge data table
- NodesAccessor API: Dynamic node access
Additional Methods¶
filter(predicate)¶
Filter.
Parameters:
- predicate: predicate
Returns:
- None: Return value
Example:
filter_by_attr(value)¶
Filter By Attr.
Parameters:
- value: value
Returns:
- None: Return value
Example:
from_csv(path)¶
From Csv.
Parameters:
- path: path
Returns:
- None: Return value
Example:
from_dict(data)¶
From Dict.
Parameters:
- data: data
Returns:
- None: Return value
Example:
from_json(path)¶
From Json.
Parameters:
- path: path
Returns:
- None: Return value
Example:
from_parquet(path)¶
From Parquet.
Parameters:
- path: path
Returns:
- None: Return value
Example:
interactive()¶
Interactive.
Returns:
- str: Return value
Example:
interactive_embed()¶
Interactive Embed.
Returns:
- str: Return value
Example:
interactive_viz()¶
Interactive Viz.
Returns:
- VizAccessor: Return value
Example:
into_base_table()¶
Into Base Table.
Returns:
- BaseTable: Return value
Example:
ncols()¶
Ncols.
Returns:
- int: Return value
Example:
rich_display()¶
Rich Display.
Returns:
- str: Return value
Example:
slice(start, end)¶
Slice.
Parameters:
- start: start
- end: end
Returns:
- None: Return value
Example:
sort_values()¶
Sort Values.
Returns:
- NodesTable: Return value
Example:
tail()¶
Tail.
Returns:
- NodesTable: Return value
Example:
to_json(path)¶
To Json.
Parameters:
- path: path
Returns:
- None: Return value
Example:
to_parquet(path)¶
To Parquet.
Parameters:
- path: path
Returns:
- None: Return value
Example:
unique_attr_values()¶
Unique Attr Values.
Returns:
- None: Return value
Example:
viz()¶
Viz.
Returns:
- VizAccessor: Return value
Example:
with_attributes(attributes)¶
With Attributes.
Parameters:
- attributes: attributes
Returns:
- None: Return value
Example: