继续前面的练习,之前的文章参考:
- pandas实例-了解你的数据-Chipotle
- pandas实例-筛选与排序-Chipotle
- pandas实例-数据可视化-Chipotle
- pandas实例-了解你的数据-Occupation
- pandas实例-筛选与过滤-Euro 12
- pandas实例-筛选与过滤-Fictional Army
- pandas实例-聚合-Alcohol Consumption
- pandas实例-聚合-Occupation
- pandas实例-聚合-Regiment
- pandas实例-Apply-Student Alcohol Consumption
- pandas实例-Apply-Crime Rates
- pandas实例-Merge-MPG Cars
- pandas实例-Merge-Fictitious Names
- pandas实例-merge-House Market
- pandas实例-Stats-US_Baby_Names
- pandas实例-Stats-Wind Statistics
- pandas实例-Visualization-Titanic_Desaster
- pandas实例-Visualization-Scores
- pandas实例-Visualization-Online Retail
- pandas实例-Visualization-Tips
- pandas实例-Time Series-Apple Stock
先看数据集
url = 'https://archive.ics.uci.edu/ml/machine-learning-databases/wine/wine.data'
df = pd.read_csv(url)
1. Delete the first, fourth, seventh, nineth, eleventh, thirteenth and fourteenth columns
删除某些列
drops = pd.Series([1,4,7,9,11,13,14])
df.columns[drops-1]
df.drop(columns=df.columns[drops-1] , inplace=True)
2. Assign the columns as below:
这一题,就是指定列名,直接来吧,但是有个问题,就是当前的column就没了,这里占位的其实是数据
df.columns=['alcohol', 'malic_acid', 'alcalinity_of_ash', 'magnesium', 'flavanoids', 'proanthocyanins', 'hue']
3. Set the values of the first 3 rows from alcohol as NaN
## Set the values of the first 3 rows from alcohol as NaN
df.iloc[:3] = np.nan
4. Now set the value of the rows 3 and 4 of magnesium as NaN
# Now set the value of the rows 3 and 4 of magnesium as NaN
df.loc[3:5 , 'magnesium'] = np.nan
哦,上一题我做错了,哈哈哈,我把所有列都设置为nan了
5. Fill the value of NaN with the number 10 in alcohol and 100 in magnesium
df['alcohol'].fillna(10 , inplace=True)
df['magnesium'].fillna(100 , inplace=True)
6. Count the number of missing values
df.isna().sum()
我这里是有缺失值的,但是原文没有,注意下
后面还有几题,我看比较类似,就算了,到这吧,哈