In [1]:
import pandas as pd

In [2]:
df = pd.read_csv('data/src/sample_header.csv')
print(df)


    a   b   c   d
0  11  12  13  14
1  21  22  23  24
2  31  32  33  34

In [3]:
s = df['c']
print(s)


0    13
1    23
2    33
Name: c, dtype: int64

In [4]:
s_f = s.astype('float64')
print(s_f)


0    13.0
1    23.0
2    33.0
Name: c, dtype: float64

In [5]:
print(s)


0    13
1    23
2    33
Name: c, dtype: int64

In [6]:
s_f = s.astype('float')
print(s_f.dtype)


float64

In [7]:
s_f = s.astype(float)
print(s_f.dtype)


float64

In [8]:
s_f = s.astype('f8')
print(s_f.dtype)


float64

In [9]:
s_s = s.astype(str)
print(s_s)


0    13
1    23
2    33
Name: c, dtype: object

In [10]:
print(s_s.map(type))


0    <class 'str'>
1    <class 'str'>
2    <class 'str'>
Name: c, dtype: object

In [11]:
s_o = s.astype('object')
print(s_o)


0    13
1    23
2    33
Name: c, dtype: object

In [12]:
print(s_o.map(type))


0    <class 'int'>
1    <class 'int'>
2    <class 'int'>
Name: c, dtype: object

In [13]:
print(df)


    a   b   c   d
0  11  12  13  14
1  21  22  23  24
2  31  32  33  34

In [14]:
print(df.dtypes)


a    int64
b    int64
c    int64
d    int64
dtype: object

In [15]:
df_f = df.astype('float64')
print(df_f)


      a     b     c     d
0  11.0  12.0  13.0  14.0
1  21.0  22.0  23.0  24.0
2  31.0  32.0  33.0  34.0

In [16]:
print(df_f.dtypes)


a    float64
b    float64
c    float64
d    float64
dtype: object

In [17]:
df_fcol = df.astype({'a': float})
print(df_fcol)


      a   b   c   d
0  11.0  12  13  14
1  21.0  22  23  24
2  31.0  32  33  34

In [18]:
print(df_fcol.dtypes)


a    float64
b      int64
c      int64
d      int64
dtype: object

In [19]:
df_fcol2 = df.astype({'a': 'float32', 'c': 'int8'})
print(df_fcol2)


      a   b   c   d
0  11.0  12  13  14
1  21.0  22  23  24
2  31.0  32  33  34

In [20]:
print(df_fcol2.dtypes)


a    float32
b      int64
c       int8
d      int64
dtype: object