我有下面的代碼給我幾乎正是我想要的:輸出不必要的陣列,熊貓
def stateCountAsList(filepath,state):
import pandas as pd
pd.set_option('display.width',200)
import numpy as np
dataFrame = pd.read_csv(filepath,header=0,sep='\t')
df = dataFrame.iloc[0:638,:]
dfState = df[df['State']== state]
yearList = range(1999,2012)
countsList =[]
for year in yearList: #for every year in the range
if year in dfState['Year'].tolist(): #if the year is in the list of years for the selected state
value = dfState[(dfState.Year == year)]
countsList.append(value.Count.values)
else:
countsList.append(np.nan.values)
print countsList
return countsList
stateCountAsList('United States Cancer Statistics, 1999-2011 Incidencet.txt' ,'California')
。
的問題是,我出來就把應該是一個清單,但我得到了這個詞到處數組:
[array([ 5561.]), array([ 5588.]), array([ 6059.]), array([ 6043.]), array([ 5958.]), array([ 6566.]), array([ 7160.]), array([ 6780.]), array([ 7327.]), array([ 7585.]), array([ 7483.]), array([ 7635.]), array([ 7735.])]
如何刪除數組中我輸出?
冷靜,得到了它。謝謝! – madman