这是我的Data和代码位:
states = pd.DataFrame(census_df['STNAME'],census_df['COUNTY'] ,)
index = census_df(['STNAME'])
州名和县的长度相等,但显示错误。
Error : __init__() got multiple values for argument 'index'
可以请任何人帮助我吗?提前谢谢!
答案 0 :(得分:0)
如果您确实希望STNAME
同时成为索引和列,那么您将缺少[]
括号。尝试:
states = pd.DataFrame([census_df['STNAME'],census_df['COUNTY']] , index = census_df['STNAME'] )
如果您的意思是希望STNAME
作为索引而COUNTY
作为列,那么您需要
states = pd.DataFrame(census_df['COUNTY'], index = census_df['STNAME'] )
或
states = pd.Series(census_df['COUNTY'], index = census_df['STNAME'] )
取决于您是要使用Series
还是DataFrame
对象。
答案 1 :(得分:0)
试试这个:
states = pd.DataFrame(census_df['STNAME'],census_df['COUNTY'])
states = states.set_index(census_df['STNAME'])