一、在数据集中随机取数

ufo.sample()
Pandas使用教程(六)
利用此方法可以划分训练集和测试集。比如随机取75%的数据作为训练集,剩下的25%作为测试集:
Pandas使用教程(六)

二、How to create dummy variables in pandas?

method1:
Pandas使用教程(六)
method2(更简洁):
Pandas使用教程(六)
Pandas使用教程(六)
将dummy columns加入到原来的DataFrame:pd.concat()
Pandas使用教程(六)
bonus:最简洁的写法!
Pandas使用教程(六)
Pandas使用教程(六)

三、How to work with dates and times in pandas?

example1:
Pandas使用教程(六)
example2:
Pandas使用教程(六)
转换成日期类型的好处:更方便的处理日期,比如:

ufo.Time.dt.weekday_name
ufo.Time.dt.weekday
ufo.Time.dt.dayofyear

example3:时间戳
Pandas使用教程(六)
example4:数学操作
Pandas使用教程(六)
bonus:统计每年ufo报道的次数并绘图(可视化)
Pandas使用教程(六)

四、How to find and remove duplicate rows in pandas?

Pandas使用教程(六)
keep=False:查看所有重复的rows
Pandas使用教程(六)
删除重复:drop_duplicates()
Pandas使用教程(六)

相关文章:

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