I'd like to declare different types for the columns of a pandas DataFrame at instantiation:
frame = pandas.DataFrame({..some data..},dtype=[str,int,int])
This works if dtype is only one type (e.g dtype=float), but not multiple types as above - is there a way to do this?
The common solution seems to be to cast later:
frame['some column'] = frame['some column'].astype(float)
but this has a couple of issues:
- It's messy
- Looks like it involves an unnecessary copy operation - this could be expensive on large data sets.