一、Difference between loc,iloc and ix

1.loc
Pandas使用教程(五)
2.iloc
loc与iloc的不同:列表切片:iloc不包含右侧,loc包含右侧。因为loc基于label,而iloc基于location
Pandas使用教程(五)
3.ix
ix不建议使用,因为当label是数值型时,使用loc的规则,当label是字符串型时,使用iloc规则
Pandas使用教程(五)

二、When to use the “inplace” parameter in pandas?

使用drop删除某个列时,未指定inplace=True,实际并未删除此列
Pandas使用教程(五)
而使用inplace=True才是真正的删除
Pandas使用教程(五)
ufo.set_index(‘Time’, inplace=True)和ufo = ufo.set_index(‘Time’)结果一样,但执行方式不同,后者会复制一遍,故运行速度慢。

三、How to make my pandas DataFrame smaller and faster?

drinks.info()
Pandas使用教程(五)
Pandas使用教程(五)

drinks[‘continent’] = drinks.continent.astype(‘category’)
Pandas使用教程(五)
将string转化为int
Pandas使用教程(五)
再次查看内存使用空间:
Pandas使用教程(五)
发现比之前小了很多

drinks.country.cat.categories

先将某个series转换成category类型,然后使用drinks.country.cat.categories查看
Pandas使用教程(五)

How to create a DataFrame:
Pandas使用教程(五)

四、How to use pandas with scikit-learn to create Kaggle submissions?

Pandas使用教程(五)
下图缺少Survival字段,因为要用于预测

Pandas使用教程(五)

编写代码并进行预测:
Pandas使用教程(五)
将结果保存到csv文件中:
Pandas使用教程(五)
bonus:将数据存储在磁盘上,.pkl是python中保存文件的一种方式:train.to_pickle()
Pandas使用教程(五)

相关文章:

  • 2021-08-31
  • 2022-12-23
  • 2022-12-23
  • 2021-09-30
  • 2021-07-13
  • 2022-01-05
  • 2021-08-02
  • 2021-10-22
猜你喜欢
  • 2021-04-06
  • 2021-04-01
  • 2021-08-03
  • 2022-01-09
  • 2021-07-24
  • 2021-06-23
  • 2021-09-05
相关资源
相似解决方案