JavaScript
x
2
1
ddf = dd.read_csv("data/csvs/*.part", dtype=better_dtypes)
2
Is there an easy equivalent way to convert all columns in a dask df(converted from a pandas df) using a dictionary. I have a dictionary as follows:
JavaScript
1
12
12
1
better_dtypes = {
2
"id1": "string[pyarrow]",
3
"id2": "string[pyarrow]",
4
"id3": "string[pyarrow]",
5
"id4": "int64",
6
"id5": "int64",
7
"id6": "int64",
8
"v1": "int64",
9
"v2": "int64",
10
"v3": "float64",
11
}
12
and would like to convert the pandas|dask df dtypes all at once to the suggested dtypes in the dictionary.
JavaScript
1
2
1
ddf = ddf.astype(better_dtypes).dtypes
2
Advertisement
Answer
Not sure if I understand the question correctly, but the conversion of dtypes can be done using .astype
(as you wrote), except you would want to remove .dtype
from the assignment:
JavaScript
1
3
1
# this will store the converted ddf
2
ddf = ddf.astype(better_dtypes)
3