DataFrame.tensor
Return a Tensorflow tensor representation of the DataFrame. Only the values in the DataFrame will be returned, the axes labels will be removed.
danfo.DataFrame.tensor [source]
Returns:
return tf.tensor
Note: Tensorflow tensors have single dtype, and will replace any string value with NaN. Use with care.

Examples

Node
Browser
1
const dfd = require("danfojs-node")
2
3
let data = { "A": [-20, 30, 47.3, -20] ,
4
"B": [34, -4, 5, 6] ,
5
"C": [20, 20, 30, 30]}
6
7
let df = new dfd.DataFrame(data)
8
let tf_tensor = df.tensor
9
10
console.log(tf_tensor.dtype);
11
12
console.log(tf_tensor);
13
14
tf_tensor.print()
Copied!
1
Copied!
Output
1
float32
2
Tensor
3
[[-20 , 34, 20],
4
[30 , -4, 20],
5
[47.2999992, 5 , 30],
6
[-20 , 6 , 30]]
Copied!
String values in a Tensor are represented as NaN, so ensure to transform them before working with tensor representations.
Node
Browser
1
const dfd = require("danfojs-node")
2
3
let data = { "Abs": [20.2, 30, 47.3] ,
4
"Count": [34, 5, 6] ,
5
"country code": ["NG", "FR", "GH"] }
6
7
8
let df = new dfd.DataFrame(data)
9
let tf_tensor = df.tensor
10
11
console.log(tf_tensor.dtype);
12
13
console.log(tf_tensor);
14
15
tf_tensor.print()
Copied!
1
Copied!
Output
1
float32
2
3
Tensor {
4
kept: false,
5
isDisposedInternal: false,
6
shape: [ 3, 3 ],
7
dtype: 'float32',
8
size: 9,
9
strides: [ 3 ],
10
dataId: {},
11
id: 0,
12
rankType: '2'
13
}
14
15
Tensor
16
[[20.2000008, 34, NaN],
17
[30 , 4 , NaN],
18
[47.2999992, 5 , NaN]]
Copied!
Last modified 17d ago
Copy link
Contents
Examples