import numpy as np
import pandas as pd
Create a Series by passing a list of values with a default integer index:
s = pd.Series([1, 4, np.nan, 6, 8])
s
Create a DataFrame using a NumPy array, with a datetime index and labeled columns:
dates = pd.date_range('20190101', periods=8)
dates
df = pd.DataFrame(np.random.randn(8, 4), index=dates, columns=list('PQRS'))
df
Create a DataFrame by passing a dict of objects that can be converted to series-like.
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'})
df2
The columns of the above DataFrame have different dtypes.
df2.dtypes