易错点1:
import pandas as pd
data=pd.read_csv("dogNames2.csv")
print(data)
data[800<data["Count_AnimalName"]<10000]
print(data[800<data["Count_AnimalName"]<10000])
报错: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
修改为:
data[(800<data["Count_AnimalName"])&(data["Count_AnimalName"]<1000)] print(data[(800<data["Count_AnimalName"])&(data["Count_AnimalName"]<1000)])
1.缺失数据的处理
x = [ {"one":1,"two":2},{"one":5,"two":10,"three":15},{"one":5,"two":10,"three":15}]
df = pd.DataFrame(x)
print(df)
# print("mean111\n",df.mean())
# print(df.fillna(df.mean()))
#操作某一列改变数值
print(df["three"].mean())
df["three"]=df["three"].fillna(df["three"].mean())
print(df)
处理为0的数据
t[t==0]=np.nan
转化为nan,可以在数组中进行运算,不影响,不进行运算。(numpy中nan做运算都为nan)
两个代码可以细品:
temp_actors_list = df["Actors"].str.split(", ").tolist()
temp_actors_list打印出来:
[['Chris Pratt', 'Vin Diesel', 'Bradley Cooper', 'Zoe Saldana'], ['Noomi Rapace', 'Logan Marshall-Green', 'Michael Fassbender', 'Charlize Theron'],
1.actors_list = [i for j in temp_actors_list for i in j] 将temp_actors_list平铺.
['Chris Pratt', 'Vin Diesel', 'Bradley Cooper', 'Zoe Saldana', 'Noomi Rapace', 'Logan Marshall-Green'...]