pandas
add_edge_attributes
¶
Add (temporal) edge attributes from pandas data frame to existing Graph
.
Add edge attributes from pandas.DataFrame
to existing Graph
, where source/target node
IDs are given in columns v
and w
and edge attributes x are given in columns edge_x
.
If time_attr
is not None, the dataframe is expected to contain temporal data with a timestamp
in a column named as specified in time_attr
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
pandas.DataFrame
|
A DataFrame with rows containing edges and optional edge attributes. |
required |
g
|
pathpyG.core.graph.Graph
|
The graph to which the edge attributes should be added. |
required |
time_attr
|
str | None
|
If not None, the name of the column containing time stamps for temporal edges. |
None
|
Source code in src/pathpyG/io/pandas.py
add_node_attributes
¶
Add node attributes from DataFrame
to existing Graph
.
Add node attributes from pandas.DataFrame
to existing graph, where node
IDs or indices are given in column v
and node attributes x are given in columns node_x
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
pandas.DataFrame
|
A DataFrame with rows containing nodes and optional node attributes. |
required |
g
|
pathpyG.core.graph.Graph
|
The graph to which the node attributes should be added. |
required |
Source code in src/pathpyG/io/pandas.py
df_to_graph
¶
Reads a network from a pandas data frame.
The data frame is expected to have a minimum of two columns that give the source and target nodes of edges. Additional columns in the data frame will be mapped to edge attributes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
pandas.DataFrame
|
A data frame with rows containing edges and optional edge attributes. If the data frame contains column names, the source and target columns must be called 'v' and 'w' respectively. If no column names are used the first two columns are interpreted as source and target. |
required |
is_undirected
|
bool
|
Whether or not to interpret edges as undirected. |
False
|
multiedges
|
bool
|
Whether or not to allow multiple edges between the same node pair. By default multi edges are ignored. |
False
|
num_nodes
|
int | None
|
The number of nodes in the graph. If None, the number of unique nodes in the data frame is used. |
None
|
Example
Source code in src/pathpyG/io/pandas.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
|
df_to_temporal_graph
¶
Read a temporal graph from a DataFrame.
The DataFrame is expected to have a minimum of two columns v
and w
that give the source and target nodes of edges. Each row in the DataFrame is
mapped to one temporal edge. Additional columns in the DataFrame will be
mapped to edge attributes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
pandas.DataFrame
|
pandas.DataFrame with rows containing time-stamped edges and optional edge attributes. |
required |
multiedges
|
bool
|
Whether or not to allow multiple edges between the same node pair. By default multi edges are ignored. |
False
|
timestamp_format
|
The format of the time stamps in the |
'%Y-%m-%d %H:%M:%S'
|
|
time_rescale
|
The factor by which to rescale the time stamps. Defaults to 1, meaning no rescaling. |
1
|
|
num_nodes
|
int | None
|
The number of nodes in the graph. If None, the number of unique nodes in the DataFrame is used. |
None
|
Example
Source code in src/pathpyG/io/pandas.py
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 |
|
graph_to_df
¶
Return a DataFrame for a given graph.
Returns a pandas.DataFrame
that contains all edges including edge
attributes. Node and network-level attributes are not included. To
facilitate the import into network analysis tools that only support integer
node identifiers, node uids can be replaced by a consecutive, zero-based
index.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
graph
|
pathpyG.core.graph.Graph
|
The graph to export as pandas DataFrame |
required |
node_indices
|
typing.Optional[bool]
|
whether nodes should be exported as integer indices |
False
|
Example
Source code in src/pathpyG/io/pandas.py
read_csv_graph
¶
Read a Graph
from a csv file.
This method reads a graph from a .csv
-file and converts it to a
Graph
object. To read a temporal graph, the csv file must have
a header with column t
containing time stamps of edges
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename
|
str
|
The path to the csv file containing the graph data. |
required |
sep
|
str
|
character separating columns in the csv file |
','
|
header
|
bool
|
whether or not the first line of the csv file is interpreted as header with column names |
True
|
is_undirected
|
bool
|
whether or not to interpret edges as undirected |
False
|
multiedges
|
bool
|
whether or not to allow multiple edges between the same node pair. By default multi edges are ignored. |
False
|
**kwargs
|
typing.Any
|
Additional keyword arguments passed to the |
{}
|
Example
Source code in src/pathpyG/io/pandas.py
read_csv_temporal_graph
¶
Read a TemporalGraph
from a csv file.
This method reads a temporal graph from a .csv
-file and converts it to a
TemporalGraph
object. The csv file is expected to have a header with columns
v
, w
, and t
containing source nodes, target nodes, and time stamps of edges,
respectively. Additional columns in the csv file will be interpreted as edge attributes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename
|
str
|
The path to the csv file containing the temporal graph data. |
required |
sep
|
str
|
character separating columns in the csv file |
','
|
header
|
bool
|
whether or not the first line of the csv file is interpreted as header with column names |
True
|
timestamp_format
|
str
|
The format of the time stamps in the |
'%Y-%m-%d %H:%M:%S'
|
time_rescale
|
int
|
The factor by which to rescale the time stamps. Defaults to 1, meaning no rescaling. |
1
|
**kwargs
|
typing.Any
|
Additional keyword arguments passed to the |
{}
|
Source code in src/pathpyG/io/pandas.py
temporal_graph_to_df
¶
Return a DataFrame for a given temporal graph.
Returns a pandas.DataFrame
that contains all edges including edge
attributes. Node and network-level attributes are not included. To
facilitate the import into network analysis tools that only support integer
node identifiers, node uids can be replaced by a consecutive, zero-based
index.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
graph
|
pathpyG.core.temporal_graph.TemporalGraph
|
The graph to export as pandas DataFrame |
required |
node_indices
|
typing.Optional[bool]
|
whether nodes should be exported as integer indices |
False
|
Example
Source code in src/pathpyG/io/pandas.py
write_csv
¶
Store all edges including edge attributes in a csv file.
This method stores a Graph
or TemporalGraph
as a .csv
file. The csv file
will contain all edges including edge attributes. Node and network-level attributes
are not included. To facilitate the import into network analysis tools that only
support integer node identifiers, node uids can be replaced by a consecutive,
zero-based index.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
graph
|
typing.Union[pathpyG.core.graph.Graph, pathpyG.core.temporal_graph.TemporalGraph]
|
The graph to export as pandas DataFrame |
required |
node_indices
|
bool
|
whether nodes should be exported as integer indices |
False
|
**pdargs
|
typing.Any
|
Additional keyword arguments passed to |
{}
|