Task: I am trying to categorize numerical values of age into the ranges 'young', 'adult', and 'elderly' through binning.
A question with a similar error was asked before but it was not answered.
Is there possibly any other alternatives to performing the intended task?
Here is my code:
bins = np.linspace(dataframe['Age'], max(dataframe['Age']), 4)
bins.sort()
group_names = ['young', 'adult', 'elderly']
dataframe['Age-binned'] = pd.cut(
dataframe['Age'], bins,
labels = group_names,
include_lowest = True
)
The error comes from the line:
dataframe['Age-binned'] = pd.cut(
dataframe['Age'], bins,
labels = group_names,
include_lowest = True
)
and yields:
ValueError: Buffer has wrong number of dimensions (expected 1, got 2)
Did you try bins = np.linspace(min(dataframe['Age']), max(dataframe['Age']), 4)?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.