1

I am new to python and jupyter notebook.

I want to tansfer(or extract) numbers in a panda series.

for example I have a panda series x

x=pd.Series(15)
print(x)
type(x)

0    15
dtype: int64
pandas.core.series.Series

and I want only the number 15 as an integer

x=15
print(x)
type(x)

15
int

how to transfer the panda series to a single number?

pault
  • 37,170
  • 13
  • 92
  • 132
Liming Zhu
  • 121
  • 2
  • 5

2 Answers2

2

If you only want to print the numbers of the series, then you can do:

x = pd.Series(15)
print(x.values)
print(x.dtype)

The output is

[15]
int64
vb_rises
  • 1,689
  • 1
  • 7
  • 13
1

Use .values property:

x=[3,5,7]
s=pd.Series(x)
s.values

Out[]: array([3, 5, 7], dtype=int64)

It will return values of the Series as numpy array.

igrinis
  • 11,051
  • 15
  • 39