1. The way to create a DataFrame with its own index and certain columns.

  state_pop = pd.read_csv("state_population.csv") 

  counts = police_killings["state_fp"].value_counts() #get the value_counts() we need from certain DataFrame

  counts_index = counts.index.tolist() 

  state_index = np.arange(len(counts_index)) # Because we would like to put counts_index.index and counts_index.values as two columns in the DataFrame State. So we are going to get the number of counts_index.value and put them into a list. 

  state = pd.DataFrame({"STATE":counts.index,"Shootings":counts},index = state_index,) # To setup the index and two columns in the DataFrame

2. 

posted on 2016-10-18 07:56  阿难1020  阅读(137)  评论(0编辑  收藏  举报