The problem is simple. Here we have a dataframe with a specified datatype for columns:
df = pd.DataFrame({'A':[1,2], 'B':[3,4]})
df.A = df.A.astype('int16')
#df
A B
0 1 3
1 2 4
#df.dtypes
A int16
B int64
dtype: object
Now I zip two columns A and B into a tuple:
df['C'] = list(zip(df.A, df.B))
A B C
0 1 3 (1, 3)
1 2 4 (2, 4)
However, now the data type of values in column C are changed.
type(df.C[0][0])
#int
type(df.A[0])
#numpy.int16
How can I zip two columns and keep the datatype of each value inside the tuples, so that type(df.C[0][0]) would be int16 (same as type(df.A[0]))?