-
-
Notifications
You must be signed in to change notification settings - Fork 18.9k
Closed
Labels
CategoricalCategorical Data TypeCategorical Data TypeDuplicate ReportDuplicate issue or pull requestDuplicate issue or pull requestIO JSONread_json, to_json, json_normalizeread_json, to_json, json_normalize
Description
- I have confirmed this bug exists on the latest version of pandas.
import pandas as pd
print(pd.version)
1.2.2
Problem described in other places:
- pd.read_json ignores 'category' dtypes #21892
- BUG: Using categorical dtype in read_json #25573
- Fix read_json category dtype #30728
Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.
Code Sample, a copy-pastable example
import pandas as pd
content = '[{"score": 1,"color":"red"},{"score":10,"color":"green"}]'
dtypes_dict = {'score': 'uint8', 'colour': 'category'}
data_frame = pd.read_json(content, dtype=dtypes_dict)
print(data_frame.dtypes)
Problem description
When I run the above, I get the following dtypes for the dataframe columns:
score uint8
color object
Expected Output
score uint8
color category
Metadata
Metadata
Assignees
Labels
CategoricalCategorical Data TypeCategorical Data TypeDuplicate ReportDuplicate issue or pull requestDuplicate issue or pull requestIO JSONread_json, to_json, json_normalizeread_json, to_json, json_normalize