我正在做一个计算旧金山每个街区的犯罪总数的项目,我使用了下面的代码,但是当我尝试使用crime\u counts.dtypes验证它时,它没有将neighbource列识别为列
import pandas as pd
file_name='https://cocl.us/sanfran_crime_dataset'
df=pd.read_csv(file_name)
crime_count = df["PdDistrict"].value_counts().to_frame('C').rename_axis('Neighbourhood')
crime_count = crime_count.rename(columns = {"PdDistrict":"Neighbourhood"})
crime_count = crime_count.rename(columns = {"C":"Counts"})
crime_count
我想创建一个dataframe,它同时识别邻域和列
首先将索引名更改为
rename_axis
,然后使用参数name
将Series
转换为2列DataFrame
:相关问题 更多 >
编程相关推荐