I would like to create a pandas dataframe from a dictionary but set multiple dtypes on selected columns at creation. EDIT - should have made this clear - I have already created the dictionary and have passed it in as col_dets in this example.
df = pd.DataFrame(col_dets, index=[0]).astype(dict.fromkeys(df.columns[[3, 6, 9]], 'float64'))
I am aware the above is incorrect, but is there a method to do this? Ideally stating columns at these indices are float64 and at other indices are int64 (for example?)
Assuming this is a follow-up of your previous question and that you want to assign a different type based on column position, you could use:
Output:
Used input: