1. 学ぶ
  2. /
  3. コース
  4. /
  5. PySparkで学ぶBig Data入門

Connected

演習

DataFrame をフィルタリングする

前の演習では、主に列方向の抽出に使う select() 演算子でデータをサブセット化しました。では、条件に基づいて DataFrame をサブセット化したい場合(例:性別が Female のすべての行を選択)にはどうすればよいでしょうか。この演習では、people_df DataFrame の中から 'sex' が female と male の行をそれぞれフィルタリングして、2つの異なるデータセットを作成します。最後に、それぞれのデータセットの行数を数えます。

ワークスペースにはすでに SparkSession spark と DataFrame people_df が用意されています。

指示

100 XP
  • people_df DataFrame をフィルタリングし、sex が female のすべての行を選択して people_df_female DataFrame を作成します。
  • people_df DataFrame をフィルタリングし、sex が male のすべての行を選択して people_df_male DataFrame を作成します。
  • people_df_female と people_df_male の各 DataFrame の行数をカウントします。