In [1]:
import numpy as np
import pandas as pd

Create a Series by passing a list of values with a default integer index:

In [2]:
s = pd.Series([1, 4, np.nan, 6, 8])
s
Out[2]:
0    1.0
1    4.0
2    NaN
3    6.0
4    8.0
dtype: float64

Pandas Object creation

Create a DataFrame using a NumPy array, with a datetime index and labeled columns:

In [3]:
dates = pd.date_range('20190101', periods=8)
In [4]:
dates
Out[4]:
DatetimeIndex(['2019-01-01', '2019-01-02', '2019-01-03', '2019-01-04',
               '2019-01-05', '2019-01-06', '2019-01-07', '2019-01-08'],
              dtype='datetime64[ns]', freq='D')
In [5]:
df = pd.DataFrame(np.random.randn(8, 4), index=dates, columns=list('PQRS'))
In [6]:
df
Out[6]:
P Q R S
2019-01-01 1.308958 0.448514 -1.969631 -1.683119
2019-01-02 -0.657054 -0.553964 -0.319463 0.111603
2019-01-03 0.195870 -0.748897 -1.096235 -0.741370
2019-01-04 -0.189043 -0.100341 0.036560 -2.442494
2019-01-05 -1.369491 -0.166653 0.988827 0.980878
2019-01-06 0.333810 -2.679771 0.633593 0.973280
2019-01-07 -0.913512 -0.705596 0.973743 0.439123
2019-01-08 -0.713225 -0.362140 -0.374827 0.048942

Pandas Object creation

Create a DataFrame by passing a dict of objects that can be converted to series-like.

In [7]:
df2 = pd.DataFrame({'A': 1.,
                        'B': pd.Timestamp('20190102'),
                        'C': pd.Series(1, index=list(range(4)), dtype='float32'),
                        'D': np.array([3] * 4, dtype='int32'),
                        'E': pd.Categorical(["test", "train", "test", "train"]),
                        'F': 'foo'})
In [8]:
df2
Out[8]:
A B C D E F
0 1.0 2019-01-02 1.0 3 test foo
1 1.0 2019-01-02 1.0 3 train foo
2 1.0 2019-01-02 1.0 3 test foo
3 1.0 2019-01-02 1.0 3 train foo

The columns of the above DataFrame have different dtypes.

In [9]:
df2.dtypes
Out[9]:
A           float64
B    datetime64[ns]
C           float32
D             int32
E          category
F            object
dtype: object