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
  • 41,343
  • 15
  • 107
  • 149
Liming Zhu
  • 221
  • 1
  • 3
  • 6

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,847
  • 1
  • 9
  • 14
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
  • 12,398
  • 20
  • 45