df = pd.read_csv(file, sep=',', encoding='ISO-8859-1')
column_names = list(df.columns)
col_mapping = {'Sex ':'Sex', 'Fatal (Y/N)': 'Fatal', 'Species ' : 'Species'}
df = df.rename(columns=col_mapping, copy=False)
我已将数据转换为包含字母或其他符号的df ['Age']列的值取值NaN
df['Age'] = np.where(pd.to_numeric(df['Age'], 'coerce').notnull(), df['Age'], NaN)
我尝试使用df.dropna(df.Age)
来清除NaN
值,但它给了我:TypeError:'Series'对象是可变的,因此无法进行散列
我想知道如何设置这个问题,以及如何对结果值进行分组和计数(即18 - 25年:215,25 - 50:300)以供将来绘图
答案 0 :(得分:0)
您想使用参数df = df.dropna(subset=['Age'])
void drawBSplineCurve(vector<point> poly)
{
int n, d;
cout << "Enter degree of curve: ";
cin >> d;
n = poly.size();
vector<double> uVec;
int i;
for(i=0;i<n+d;i++)
{
uVec.push_back(((double)i)/(n+d-1));
}
double x, y, basis, u;
for(u=0;u<=1;u+=0.0001)
{
x = 0;
y = 0;
for(i=0;i<poly.size();i++)
{
basis = blend(uVec, u, i, d);
x += basis*poly[i].x;
y += basis*poly[i].y;
}
putpixel(roundOff(x), roundOff(y), YELLOW);
}
}
double blend(vector<double> &uVec, double u, int k, int d)
{
if(d==1)
{
if(uVec[k]<=u && u<uVec[k+1])
return 1;
return 0;
}
double b;
b = ((u-uVec[k])/(uVec[k+d-1]-uVec[k])*blend(uVec, u, k, d-1)) + ((uVec[k+d]-u)/(uVec[k+d]-uVec[k+1])*blend(uVec, u, k+1, d-1));
return b;
}
答案 1 :(得分:0)
我找到了答案四个分组问题:
df['Age']=df[['Age']].astype(int)
Grouped_Age = pd.cut(df.Age,[5, 10, 20, 50, 100], right=True)
Age_counts = Grouped_Age.value_counts()