Skip to content

Commit f7b6593

Browse files
committed
Add initialization from CSR matrix.
1 parent 1079a07 commit f7b6593

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

docs/sources/user_guide.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ Create a SparseFrame from numpy array:
2121
with 10 stored elements in Compressed Sparse Row format]
2222
```
2323

24-
You can also create a SparseFrame from Pandas DataFrame:
24+
You can also create a SparseFrame from Pandas DataFrame. Index and columns
25+
will be preserved:
2526
```pycon
2627
>>> import pandas as pd
2728

2829
>>> df = pd.DataFrame(a, index=np.arange(10, 20), columns=list('ABCDE'))
29-
>>> sf = sparsity.SparseFrame(df)
30-
>>> sf
30+
>>> sparsity.SparseFrame(df)
3131
A B C D E
3232
10 0.0 0.000000 0.0 0.000000 0.000000
3333
11 0.0 0.962851 0.0 0.000000 0.000000
@@ -38,6 +38,21 @@ You can also create a SparseFrame from Pandas DataFrame:
3838
with 10 stored elements in Compressed Sparse Row format]
3939
```
4040

41+
Initialization from Scipy CSR matrix is also possible. If you don't pass
42+
index or columns, defaults will be used:
43+
```pycon
44+
>>> csr = scipy.sparse.rand(10, 5, density=0.1, format='csr')
45+
>>> sparsity.SparseFrame(csr)
46+
0 1 2 3 4
47+
0 0.638314 0.0 0.000000 0.0 0.0
48+
1 0.000000 0.0 0.000000 0.0 0.0
49+
2 0.000000 0.0 0.043411 0.0 0.0
50+
3 0.000000 0.0 0.000000 0.0 0.0
51+
4 0.000000 0.0 0.222951 0.0 0.0
52+
[10x5 SparseFrame of type '<class 'float64'>'
53+
with 5 stored elements in Compressed Sparse Row format]
54+
```
55+
4156
## Indexing
4257

4358
Indexing a SparseFrame with column name gives a new SparseFrame:

0 commit comments

Comments
 (0)