美文网首页
pandas实例-Deleting(二)

pandas实例-Deleting(二)

作者: 橘猫吃不胖 | 来源:发表于2020-05-23 18:15 被阅读0次

继续前面的练习,之前的文章参考:


先看数据集

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()

我这里是有缺失值的,但是原文没有,注意下

后面还有几题,我看比较类似,就算了,到这吧,哈

相关文章

  • pandas实例-Deleting(二)

    继续前面的练习,之前的文章参考: pandas实例-了解你的数据-Chipotle pandas实例-筛选与排序-...

  • pandas实例-Deleting

    继续前面的练习,之前的文章参考: pandas实例-了解你的数据-Chipotle pandas实例-筛选与排序-...

  • pandas实例-总结

    继续前面的练习,之前的文章参考: pandas实例-了解你的数据-Chipotle pandas实例-筛选与排序-...

  • pandas实例-Visualization-Titanic_D

    继续前面的练习,之前的文章参考: pandas实例-了解你的数据-Chipotle pandas实例-筛选与排序-...

  • pandas实例-Visualization-Scores

    继续前面的练习,之前的文章参考: pandas实例-了解你的数据-Chipotle pandas实例-筛选与排序-...

  • pandas实例-merge-House Market

    继续前面的练习,之前的文章参考: pandas实例-了解你的数据-Chipotle pandas实例-筛选与排序-...

  • pandas实例-Stats-US_Baby_Names

    继续前面的练习,之前的文章参考: pandas实例-了解你的数据-Chipotle pandas实例-筛选与排序-...

  • pandas实例-Stats-Wind Statistics

    继续前面的练习,之前的文章参考: pandas实例-了解你的数据-Chipotle pandas实例-筛选与排序-...

  • pandas实例-Time Series-Apple Stock

    继续前面的练习,之前的文章参考: pandas实例-了解你的数据-Chipotle pandas实例-筛选与排序-...

  • pandas实例-Visualization-Tips

    继续前面的练习,之前的文章参考: pandas实例-了解你的数据-Chipotle pandas实例-筛选与排序-...

网友评论

      本文标题:pandas实例-Deleting(二)

      本文链接:https://www.haomeiwen.com/subject/mzdlahtx.html