In [1]:
import pandas as pd
In [2]:
df = pd.read_csv('data/src/sample_header_index_dtype.csv', index_col=0)
print(df)
In [3]:
print(df.dtypes)
In [4]:
print(df.applymap(type))
In [5]:
df_str = pd.read_csv('data/src/sample_header_index_dtype.csv',
index_col=0, dtype=str)
print(df_str)
In [6]:
print(df_str.dtypes)
In [7]:
print(df_str.applymap(type))
In [8]:
df_object = pd.read_csv('data/src/sample_header_index_dtype.csv',
index_col=0, dtype=object)
print(df_object)
In [9]:
print(df_object.dtypes)
In [10]:
print(df_object.applymap(type))
In [11]:
print(df.astype(str).applymap(type))
In [12]:
df_col = pd.read_csv('data/src/sample_header_index_dtype.csv',
index_col=0, dtype={'a': float, 'b': str})
print(df_col)
In [13]:
print(df_col.dtypes)
In [14]:
df_col = pd.read_csv('data/src/sample_header_index_dtype.csv',
index_col=0, dtype={1: float, 2: str})
print(df_col)
In [15]:
print(df_col.dtypes)