I use the following code to get the count of months in a data set
crime_rate_month = crime_data["Month"].value_counts().to_frame()
print(crime_rate_month)
I want to specify "Month" and the "Count" as the titles of the resulting columns. How can I do that? Thanks in advance.
CodePudding user response:
You can use name
and names
parameters of to_frame
and reset_index
respectively.
Try this :
crime_rate_month = (
crime_data["Month"].value_counts()
.to_frame(name="Count")
.reset_index(names=["Month"])
)
CodePudding user response:
You can use rename
to rename the resulting column:
crime_rate_month = crime_rate_month.rename(columns={
"Month": "Count"
})