Q:

Initializing series object using numpy?

As i was starting with pandas and tried to understand how to create series using given array or list, i came across this line...
If you initialize a series object with the help of NumPy then you can hold only homogeneous data within it.
I am not able to understand what it says! I guess series can hold any dtype as long as it is same throughout that particular vector, isn't it? Then what does the above line mean in this context?
here is the code written just before this statement......
import numpy as np
import pandas as pd

labels = ['a','b','c']
my_data = [10,20,30]
arr = np.array(my_data)

print(pd.Series(my_data))
print('==================')
print(pd.Series(my_data,index=labels))

A:

When you have in my_data non-homogenous items, e.g. a mixture of numbers
and strings, e.g.:
labels = ['a', 'b', 'c', 'd', 'e']
my_data = [10, 20, 30, 'xx', 12.55]
arr = np.array(my_data)
s = pd.Series(my_data, index=labels)

and print arr, you will get:
array(['10', '20', '30', 'xx', '12.55'], dtype='<U11')

Note that each item in arr is a string.
At the first glance, the same holds for s. When you print it, you will get:
a       10
b       20
c       30
d       xx
e    12.55
dtype: object

When you look at the items itself, it is not obvious what is their type, but look
at the bottom line: dtype: object.
The first thought is "actually a string", but as a matter of fact it means
"it depends from particular cell".
To confirm it, take a look at individual cells:
type(s['a']) yields int, type(s['d']) yields str and
type(s['e']) yields float (each of them are descendants of object).
And now try the homogenous variant:
my_data = [10, 20, 30, 4.12, 12.55]

(either int or float, other "initial" instructions like above).
Now when you print arr, you will get:
array([10.  , 20.  , 30.  ,  4.12, 12.55])

so all elements are coerced to closest possible ancestor, in this
case just float.
When you print s, the result is:
a    10.00
b    20.00
c    30.00
d     4.12
e    12.55
dtype: float64

so its type is inherited from arr.
This time, when you print type(s['a']) (or whathever other cell),
you will get float.
Note also such a difference between plain pythonic list and a Numpy array:

in a list each element has its own type,
in a Numpy array the type is assigned to the array, i.e.
all its elements have the same type (although they can be subtypes
of the "basic" type for the whole array).

So when you create a Series or DataFrame from Numpy array (1-D or 2-D
respectively):

Series object inherits type from the source array,
each column of a DataFrame also inherit type from this array.

Of course, you can create a DataFrame also from a number of separate 1-D
Numpy arrays (sources for columns), each with its own type and the
resulting DataFrame also will inherit source types, separately
for each column, from respective Numpy arrays.
Edit following the question
Only as late as in version 1.0 of Pandas there were introduced some
new, experimental dtypes, among them string (just what you ask for).
Apparently Pandas authors recognized that there is a need for an "explicit"
string, not "any object, maybe a string".
But these changes are introduced stepwise, for now not including existing
methods to read content from files.
E.g. read_csv operates "the old way", i.e. if some column is of
non-numerical and non-datelike type, then object type is assumed.
To allow conversion of such columns to "new" dtypes, convert_dtypes()
method has been added, to be called e.g. after read_csv, in an attempt
to change the type of each column to some of "new" dtypes (if possible).
To get more complete image of what was recenty added, and how to use it,
read the Pandas documentation about new dtypes, NA scalar and
working with missing data.

