input
stringlengths
0
929
output
stringlengths
0
10.3k
task
stringclasses
3 values
index
int64
0
5.38k
liscence
stringclasses
4 values
source
stringclasses
15 values
instruction
stringlengths
13
3.45k
import pandas as pd df_receipt.head(10)
code_generation
0
MIT
datascience_100_knocks_python
pandasでレシート明細データ(df_receipt)から全項目の先頭10件を表示し、どのようなデータを保有しているか目視で確認せよ。
import pandas as pd df_receipt[['sales_ymd', 'customer_id', 'product_cd', 'amount']].head(10)
code_generation
1
MIT
datascience_100_knocks_python
pandasでレシート明細データ(df_receipt)から売上年月日(sales_ymd)、顧客ID(customer_id)、商品コード(product_cd)、売上金額(amount)の順に列を指定し、10件表示せよ。
import pandas as pd df_receipt[['sales_ymd', 'customer_id', 'product_cd', 'amount']]. \ rename(columns={'sales_ymd': 'sales_date'}).head(10)
code_generation
2
MIT
datascience_100_knocks_python
pandasでレシート明細データ(df_receipt)から売上年月日(sales_ymd)、顧客ID(customer_id)、商品コード(product_cd)、売上金額(amount)の順に列を指定し、10件表示せよ。ただし、sales_ymdsales_dateに項目名を変更しながら抽出すること。
import pandas as pd # コード例1(queryを使う場合) df_receipt[['sales_ymd', 'customer_id', 'product_cd', 'amount']]. \ query('customer_id == "CS018205000001"') # コード例1(queryを使わない場合) df = df_receipt[['sales_ymd', 'customer_id', 'product_cd', 'amount']] df[df['customer_id'] == 'CS018205000001']
code_generation
3
MIT
datascience_100_knocks_python
pandasでレシート明細データ(df_receipt)から売上日(sales_ymd)、顧客ID(customer_id)、商品コード(product_cd)、売上金額(amount)の順に列を指定し、以下の条件を満たすデータを抽出せよ。
import pandas as pd df_receipt[['sales_ymd', 'customer_id', 'product_cd', 'amount']] \ .query('customer_id == "CS018205000001" & amount >= 1000')
code_generation
4
MIT
datascience_100_knocks_python
pandasを用いてシート明細データ(df_receipt)から売上日(sales_ymd)、顧客ID(customer_id)、商品コード(product_cd)、売上金額(amount)の順に列を指定し、以下の全ての条件を満たすデータを抽出せよ。 顧客ID(customer_id)が"CS018205000001" 売上金額(amount)が1,000以上
df_receipt[['sales_ymd', 'customer_id', 'product_cd', 'quantity', 'amount']].\ query('customer_id == "CS018205000001" & (amount >= 1000 | quantity >=5)')
code_generation
5
MIT
datascience_100_knocks_python
pandasを用いてレシート明細データ(df_receipt)から売上日(sales_ymd)、顧客ID(customer_id)、商品コード(product_cd)、売上数量(quantity)、売上金額(amount)の順に列を指定し、以下の全ての条件を満たすデータを抽出せよ。 顧客ID(customer_id)が"CS018205000001" 売上金額(amount)が1,000以上または売上数量(quantity)が5以上
import pandas as pd df_receipt[['sales_ymd', 'customer_id', 'product_cd', 'amount']] \ .query('customer_id == "CS018205000001" & 1000 <= amount <= 2000')
code_generation
6
MIT
datascience_100_knocks_python
pandasを用いてレシート明細データ(df_receipt)から売上日(sales_ymd)、顧客ID(customer_id)、商品コード(product_cd)、売上金額(amount)の順に列を指定し、以下の全ての条件を満たすデータを抽出せよ。 顧客ID(customer_id)が"CS018205000001" 売上金額(amount)が1,000以上2,000以下
import pandas as pd df_receipt[['sales_ymd', 'customer_id', 'product_cd', 'amount']] \ .query('customer_id == "CS018205000001" & product_cd != "P071401019"')
code_generation
7
MIT
datascience_100_knocks_python
pandasを用いてレシート明細データ(df_receipt)から売上日(sales_ymd)、顧客ID(customer_id)、商品コード(product_cd)、売上金額(amount)の順に列を指定し、以下の全ての条件を満たすデータを抽出せよ。 顧客ID(customer_id)が"CS018205000001" 商品コード(product_cd)が"P071401019"以外
import pandas as pd df_store.query('prefecture_cd != "13" & floor_area <= 900')
code_generation
8
MIT
datascience_100_knocks_python
pandasを用いて以下の処理において、出力結果を変えずにORをANDに書き換えよ。 df_store.query('not(prefecture_cd == "13" | floor_area > 900)')
import pandas as pd df_store.query("store_cd.str.startswith('S14')", engine='python').head(10)
code_generation
9
MIT
datascience_100_knocks_python
pandasを用いて店舗データ(df_store)から、店舗コード(store_cd)が"S14"で始まるものだけ全項目抽出し、10件表示せよ。
import pandas as pd df_customer.query("customer_id.str.endswith('1')", engine='python').head(10)
code_generation
10
MIT
datascience_100_knocks_python
pandasを用いて顧客データ(df_customer)から顧客ID(customer_id)の末尾が1のものだけ全項目抽出し、10件表示せよ。
import pandas as pd df_store.query("address.str.contains('横浜市')", engine='python')
code_generation
11
MIT
datascience_100_knocks_python
pandasを用いて店舗データ(df_store)から、住所 (address) に"横浜市"が含まれるものだけ全項目表示せよ。
import pandas as pd df_customer.query("status_cd.str.contains(r'^[A-F]')", engine='python').head(10)
code_generation
12
MIT
datascience_100_knocks_python
pandasを用いて顧客データ(df_customer)から、ステータスコード(status_cd)の先頭がアルファベットのA〜Fで始まるデータを全項目抽出し、10件表示せよ。
import pandas as pd # regexのオプションをつけることもできる(Falseにすれば正規表現ではなくそのままの文字列として扱われる) df_customer.query("status_cd.str.contains(r'[1-9]$', regex=True)", engine='python').head(10)
code_generation
13
MIT
datascience_100_knocks_python
pandasを用いて顧客データ(df_customer)から、ステータスコード(status_cd)の末尾が数字の1〜9で終わるデータを全項目抽出し、10件表示せよ。
import pandas as pd df_customer.query("status_cd.str.contains(r'^[A-F].*[1-9]$')", engine='python').head(10)
code_generation
14
MIT
datascience_100_knocks_python
pandasを用いて顧客データ(df_customer)から、ステータスコード(status_cd)の先頭がアルファベットのA〜Fで始まり、末尾が数字の1〜9で終わるデータを全項目抽出し、10件表示せよ。
import pandas as pd df_store.query("tel_no.str.contains(r'^[0-9]{3}-[0-9]{3}-[0-9]{4}$')", engine='python')
code_generation
15
MIT
datascience_100_knocks_python
pandasを用いて店舗データ(df_store)から、電話番号(tel_no)が3桁-3桁-4桁のデータを全項目表示せよ。
import pandas as pd df_customer.sort_values('birth_day').head(10)
code_generation
16
MIT
datascience_100_knocks_python
pandasを用いて顧客データ(df_customer)を生年月日(birth_day)で高齢順にソートし、先頭から全項目を10件表示せよ。
import pandas as pd df_customer.sort_values('birth_day', ascending=False).head(10)
code_generation
17
MIT
datascience_100_knocks_python
pandasを用いて顧客データ(df_customer)を生年月日(birth_day)で若い順にソートし、先頭から全項目を10件表示せよ。
import pandas as pd df_tmp = pd.concat([df_receipt[['customer_id', 'amount']] ,df_receipt['amount'].rank(method='min', ascending=False)], axis=1) df_tmp.columns = ['customer_id', 'amount', 'ranking'] df_tmp.sort_values('ranking').head(10)
code_generation
18
MIT
datascience_100_knocks_python
pandasを用いてレシート明細データ(df_receipt)に対し、1件あたりの売上金額(amount)が高い順にランクを付与し、先頭から10件表示せよ。項目は顧客ID(customer_id)、売上金額(amount)、付与したランクを表示させること。なお、売上金額(amount)が等しい場合は同一順位を付与するものとする。
import pandas as pd df_tmp = pd.concat([df_receipt[['customer_id', 'amount']] ,df_receipt['amount'].rank(method='first', ascending=False)], axis=1) df_tmp.columns = ['customer_id', 'amount', 'ranking'] df_tmp.sort_values('ranking').head(10)
code_generation
19
MIT
datascience_100_knocks_python
pandasを用いてレシート明細データ(df_receipt)に対し、1件あたりの売上金額(amount)が高い順にランクを付与し、先頭から10件表示せよ。項目は顧客ID(customer_id)、売上金額(amount)、付与したランクを表示させレシート明細データ(df_receipt)に対し、1件あたりの売上金額(amount)が高い順にランクを付与し、先頭から10件表示せよ。項目は顧客ID(customer_id)、売上金額(amount)、付与したランクを表示させること。なお、売上金額(amount)が等しい場合でも別順位を付与すること。
import pandas as pd len(df_receipt)
code_generation
20
MIT
datascience_100_knocks_python
pandasを用いてレシート明細データ(df_receipt)に対し、件数をカウントせよ。
import pandas as pd len(df_receipt['customer_id'].unique())
code_generation
21
MIT
datascience_100_knocks_python
pandasを用いてレシート明細データ(df_receipt)の顧客ID(customer_id)に対し、ユニーク件数をカウントせよ。
import pandas as pd # コード例1 df_receipt.groupby('store_cd').agg({'amount':'sum', 'quantity':'sum'}).reset_index() # コード例2 df_receipt.groupby('store_cd')[['amount','quantity']].agg('sum').reset_index()
code_generation
22
MIT
datascience_100_knocks_python
pandasを用いてレシート明細データ(df_receipt)に対し、店舗コード(store_cd)ごとに売上金額(amount)と売上数量(quantity)を合計せよ。
import pandas as pd df_receipt.groupby('customer_id').agg({'sales_ymd': 'max'}).reset_index().head(10)
code_generation
23
MIT
datascience_100_knocks_python
pandasを用いてレシート明細データ(df_receipt)に対し、顧客ID(customer_id)ごとに最も新しい売上年月日(sales_ymd)を求め、10件表示せよ。
import pandas as pd df_receipt.groupby('customer_id').sales_ymd.min().reset_index().head(10)
code_generation
24
MIT
datascience_100_knocks_python
pandasを用いてレシート明細データ(df_receipt)に対し、顧客ID(customer_id)ごとに最も古い売上年月日(sales_ymd)を求め、10件表示せよ。
import pandas as pd df_tmp = df_receipt.groupby('customer_id'). \ agg({'sales_ymd':['max','min']}).reset_index() # マルチインデックス(項目)の階層を"_"でつなぎながら1階層のインデックス(項目)にする # df_tmp.columns = ['customer_id', 'sales_ymd_max', 'sales_ymd_min'] としても良い df_tmp.columns = ["_".join(pair) for pair in df_tmp.columns] df_tmp.query('sales_ymd_max != sales_ymd_min').head(10)
code_generation
25
MIT
datascience_100_knocks_python
pandasを用いてレシート明細データ(df_receipt)に対し、顧客ID(customer_id)ごとに最も新しい売上年月日(sales_ymd)と古い売上年月日を求め、両者が異なるデータを10件表示せよ。
import pandas as pd df_receipt.groupby('store_cd').agg({'amount':'mean'}).reset_index(). \ sort_values('amount', ascending=False).head(5)
code_generation
26
MIT
datascience_100_knocks_python
pandasを用いてレシート明細データ(df_receipt)に対し、店舗コード(store_cd)ごとに売上金額(amount)の平均を計算し、降順でTOP5を表示せよ。
import pandas as pd df_receipt.groupby('store_cd').agg({'amount':'median'}).reset_index(). \ sort_values('amount', ascending=False).head(5)
code_generation
27
MIT
datascience_100_knocks_python
pandasを用いてレシート明細データ(df_receipt)に対し、店舗コード(store_cd)ごとに売上金額(amount)の中央値を計算し、降順でTOP5を表示せよ。
import pandas as pd df_receipt.groupby('store_cd').product_cd. \ apply(lambda x: x.mode()).reset_index().head(10)
code_generation
28
MIT
datascience_100_knocks_python
pandasを用いてレシート明細データ(df_receipt)に対し、店舗コード(store_cd)ごとに商品コード(product_cd)の最頻値を求め、10件表示させよ。
import pandas as pd df_receipt.groupby('store_cd').amount.var(ddof=0).reset_index(). \ sort_values('amount', ascending=False).head(5)
code_generation
29
MIT
datascience_100_knocks_python
pandasを用いてレシート明細データ(df_receipt)に対し、店舗コード(store_cd)ごとに売上金額(amount)の分散を計算し、降順で5件表示せよ。
import pandas as pd df_receipt.groupby('store_cd').amount.std(ddof=0).reset_index(). \ sort_values('amount', ascending=False).head(5) TIPS: PandasとNumpyでddofのデフォルト値が異なることに注意しましょう Pandas: DataFrame.std(self, axis=None, skipna=None, level=None, ddof=1, numeric_only=None, **kwargs) Numpy: numpy.std(a, axis=None, dtype=None, out=None, ddof=0, keepdims=)
code_generation
30
MIT
datascience_100_knocks_python
pandasを用いてレシート明細データ(df_receipt)に対し、店舗コード(store_cd)ごとに売上金額(amount)の標準偏差を計算し、降順で5件表示せよ。
import pandas as pd # コード例1 np.percentile(df_receipt['amount'], q=np.arange(1, 5) * 25) # コード例2 df_receipt.amount.quantile(q=np.arange(1, 5) / 4)
code_generation
31
MIT
datascience_100_knocks_python
pandasを用いてレシート明細データ(df_receipt)の売上金額(amount)について、25%刻みでパーセンタイル値を求めよ。
import pandas as pd df_receipt.groupby('store_cd').amount.mean(). \ reset_index().query('amount >= 330')
code_generation
32
MIT
datascience_100_knocks_python
pandasを用いてレシート明細データ(df_receipt)に対し、店舗コード(store_cd)ごとに売上金額(amount)の平均を計算し、330以上のものを抽出せよ。
import pandas as pd # コード例1: queryを使わない書き方 df_receipt[~df_receipt['customer_id'].str.startswith("Z")]. \ groupby('customer_id').amount.sum().mean() # コード例2: queryを使う書き方 df_receipt.query('not customer_id.str.startswith("Z")', engine='python').groupby('customer_id').amount.sum().mean()
code_generation
33
MIT
datascience_100_knocks_python
pandasを用いてレシート明細データ(df_receipt)に対し、顧客ID(customer_id)ごとに売上金額(amount)を合計して全顧客の平均を求めよ。ただし、顧客IDが"Z"から始まるものは非会員を表すため、除外して計算すること。
import pandas as pd df_amount_sum = df_receipt[~df_receipt['customer_id'].str.startswith("Z")].\ groupby('customer_id').amount.sum() amount_mean = df_amount_sum.mean() df_amount_sum = df_amount_sum.reset_index() df_amount_sum[df_amount_sum['amount'] >= amount_mean].head(10)
code_generation
34
MIT
datascience_100_knocks_python
pandasを用いてレシート明細データ(df_receipt)に対し、顧客ID(customer_id)ごとに売上金額(amount)を合計して全顧客の平均を求め、平均以上に買い物をしている顧客を抽出し、10件表示せよ。ただし、顧客IDが"Z"から始まるものは非会員を表すため、除外して計算すること。
import pandas as pd pd.merge(df_receipt, df_store[['store_cd','store_name']], how='inner', on='store_cd').head(10)
code_generation
35
MIT
datascience_100_knocks_python
pandasを用いてレシート明細データ(df_receipt)と店舗データ(df_store)を内部結合し、レシート明細データの全項目と店舗データの店舗名(store_name)を10件表示せよ。
import pandas as pd pd.merge(df_product , df_category[['category_small_cd','category_small_name']] , how='inner', on='category_small_cd').head(10)
code_generation
36
MIT
datascience_100_knocks_python
pandasを用いて商品データ(df_product)とカテゴリデータ(df_category)を内部結合し、商品データの全項目とカテゴリデータのカテゴリ小区分名(category_small_name)を10件表示せよ。
import pandas as pd df_amount_sum = df_receipt.groupby('customer_id').amount.sum().reset_index() df_tmp = df_customer. \ query('gender_cd == "1" and not customer_id.str.startswith("Z")', engine='python') pd.merge(df_tmp['customer_id'], df_amount_sum, how='left', on='customer_id').fillna(0).head(10)
code_generation
37
MIT
datascience_100_knocks_python
pandasを用いて顧客データ(df_customer)とレシート明細データ(df_receipt)から、顧客ごとの売上金額合計を求め、10件表示せよ。ただし、売上実績がない顧客については売上金額を0として表示させること。また、顧客は性別コード(gender_cd)が女性(1)であるものを対象とし、非会員(顧客IDが"Z"から始まるもの)は除外すること。
import pandas as pd df_data = df_receipt \ .query('not customer_id.str.startswith("Z")', engine='python') df_cnt = df_data[~df_data.duplicated(subset=['customer_id', 'sales_ymd'])] \ .groupby('customer_id').sales_ymd.count().reset_index() \ .sort_values('sales_ymd', ascending=False).head(20) df_sum = df_data.groupby('customer_id').amount.sum().reset_index() \ .sort_values('amount', ascending=False).head(20) pd.merge(df_cnt, df_sum, how='outer', on='customer_id')
code_generation
38
MIT
datascience_100_knocks_python
pandasを用いてレシート明細データ(df_receipt)から、売上日数の多い顧客の上位20件を抽出したデータと、売上金額合計の多い顧客の上位20件を抽出したデータをそれぞれ作成し、さらにその2つを完全外部結合せよ。ただし、非会員(顧客IDが"Z"から始まるもの)は除外すること。
import pandas as pd df_store_tmp = df_store.copy() df_product_tmp = df_product.copy() df_store_tmp['key'] = 0 df_product_tmp['key'] = 0 len(pd.merge(df_store_tmp, df_product_tmp, how='outer', on='key'))
code_generation
39
MIT
datascience_100_knocks_python
pandasを用いて全ての店舗と全ての商品を組み合わせたデータを作成したい。店舗データ(df_store)と商品データ(df_product)を直積し、件数を計算せよ。
import pandas as pd df_sales_amount_by_date = df_receipt[['sales_ymd', 'amount']].\ groupby('sales_ymd').sum().reset_index() df_sales_amount_by_date = pd.concat([df_sales_amount_by_date, df_sales_amount_by_date.shift()], axis=1) df_sales_amount_by_date.columns = ['sales_ymd','amount','lag_ymd','lag_amount'] df_sales_amount_by_date['diff_amount'] = \ df_sales_amount_by_date['amount'] - df_sales_amount_by_date['lag_amount'] df_sales_amount_by_date.head(10)
code_generation
40
MIT
datascience_100_knocks_python
pandasを用いてレシート明細データ(df_receipt)の売上金額(amount)を日付(sales_ymd)ごとに集計し、前回売上があった日からの売上金額増減を計算せよ。そして結果を10件表示せよ。
import pandas as pd # コード例1:縦持ちケース df_sales_amount_by_date = df_receipt[['sales_ymd', 'amount']]. \ groupby('sales_ymd').sum().reset_index() for i in range(1, 4): df_tmp = pd.concat([df_sales_amount_by_date, df_sales_amount_by_date.shift(i)], axis=1) if i == 1: df_lag = df_tmp else: # DataFrameでappendが削除されるためappend -> concatに変更 df_lag = pd.concat([df_lag, df_tmp], axis=0) df_lag.columns = ['sales_ymd', 'amount', 'lag_ymd', 'lag_amount'] df_lag.dropna().astype(int).sort_values(['sales_ymd','lag_ymd']).head(10) # コード例2:横持ちケース df_sales_amount_by_date = df_receipt[['sales_ymd', 'amount']].\ groupby('sales_ymd').sum().reset_index() df_lag = df_sales_amount_by_date for i in range(1, 4): df_lag = pd.concat([df_lag, df_sales_amount_by_date.shift(i)], axis=1) columns = [f'lag_ymd_{i}', f'lag_amount_{i}'] df_lag.columns = list(df_lag.columns)[:-len(columns)] + columns df_lag.dropna().astype(int).sort_values(['sales_ymd']).head(10)
code_generation
41
MIT
datascience_100_knocks_python
pandasを用いてレシート明細データ(df_receipt)の売上金額(amount)を日付(sales_ymd)ごとに集計し、各日付のデータに対し、前回、前々回、3回前に売上があった日のデータを結合せよ。そして結果を10件表示せよ。
import pandas as pd # コード例1 df_tmp = pd.merge(df_receipt, df_customer, how ='inner', on="customer_id") df_tmp['era'] = df_tmp['age'].apply(lambda x: math.floor(x / 10) * 10) df_sales_summary = pd.pivot_table( df_tmp, index='era', columns='gender_cd', values='amount', aggfunc='sum' ).reset_index() df_sales_summary.columns = ['era', 'male', 'female', 'unknown'] df_sales_summary # コード例2 df_tmp = pd.merge(df_receipt, df_customer, how ='inner', on="customer_id") df_tmp['era'] = np.floor(df_tmp['age'] / 10).astype(int) * 10 df_sales_summary = pd.pivot_table(df_tmp, index='era', columns='gender_cd', values='amount', aggfunc='sum').reset_index() df_sales_summary.columns = ['era', 'male', 'female', 'unknown'] df_sales_summary
code_generation
42
MIT
datascience_100_knocks_python
pandasを用いてレシート明細データ(df_receipt)と顧客データ(df_customer)を結合し、性別コード(gender_cd)と年代(ageから計算)ごとに売上金額(amount)を合計した売上サマリデータを作成せよ。性別コードは0が男性、1が女性、9が不明を表すものとする。 ただし、項目構成は年代、女性の売上金額、男性の売上金額、性別不明の売上金額の4項目とすること(縦に年代、横に性別のクロス集計)。また、年代は10歳ごとの階級とすること。
import pandas as pd df_sales_summary.set_index('era'). \ stack().reset_index().replace({'female':'01','male':'00','unknown':'99'}). \ rename(columns={'level_1':'gender_cd', 0: 'amount'})
code_generation
43
MIT
datascience_100_knocks_python
売上サマリデータ(df_sales_summary)は性別の売上を横持ちさせたものである。pandasを用いてこのデータから性別を縦持ちさせ、年代、性別コード、売上金額の3項目に変換せよ。ただし、性別コードは男性を"00"、女性を"01"、不明を"99"とする。
import pandas as pd # 以下の書き方でYYYYMMDD形式の文字列に変換できる # pd.to_datetime(df_customer['birth_day']).dt.strftime('%Y%m%d') pd.concat([df_customer['customer_id'], pd.to_datetime(df_customer['birth_day']).dt.strftime('%Y%m%d')], axis = 1).head(10)
code_generation
44
MIT
datascience_100_knocks_python
pandasを用いて顧客データ(df_customer)の生年月日(birth_day)は日付型でデータを保有している。これをYYYYMMDD形式の文字列に変換し、顧客ID(customer_id)とともに10件表示せよ。
import pandas as pd pd.concat([df_customer['customer_id'], pd.to_datetime(df_customer['application_date'])], axis=1).head(10)
code_generation
45
MIT
datascience_100_knocks_python
pandasを用いて顧客データ(df_customer)の申し込み日(application_date)はYYYYMMDD形式の文字列型でデータを保有している。これを日付型に変換し、顧客ID(customer_id)とともに10件表示せよ。
import pandas as pd pd.concat([df_receipt[['receipt_no', 'receipt_sub_no']], pd.to_datetime(df_receipt['sales_ymd'].astype('str'))], axis=1).head(10)
code_generation
46
MIT
datascience_100_knocks_python
pandasを用いてレシート明細データ(df_receipt)の売上日(sales_ymd)はYYYYMMDD形式の数値型でデータを保有している。これを日付型に変換し、レシート番号(receipt_no)、レシートサブ番号(receipt_sub_no)とともに10件表示せよ。
import pandas as pd pd.concat([df_receipt[['receipt_no', 'receipt_sub_no']], pd.to_datetime(df_receipt['sales_epoch'], unit='s').rename('sales_ymd')], axis=1).head(10)
code_generation
47
MIT
datascience_100_knocks_python
pandasを用いてレシート明細データ(df_receipt)の売上エポック秒(sales_epoch)は数値型のUNIX秒でデータを保有している。これを日付型に変換し、レシート番号(receipt_no)、レシートサブ番号(receipt_sub_no)とともに10件表示せよ。
import pandas as pd pd.concat([df_receipt[['receipt_no', 'receipt_sub_no']], pd.to_datetime(df_receipt['sales_epoch'], unit='s').dt.year.rename('sales_year')], axis=1).head(10)
code_generation
48
MIT
datascience_100_knocks_python
pandasを用いてレシート明細データ(df_receipt)の売上エポック秒(sales_epoch)を日付型に変換し、「年」だけ取り出してレシート番号(receipt_no)、レシートサブ番号(receipt_sub_no)とともに10件表示せよ。
import pandas as pd # dt.monthでも月を取得できるが、ここでは0埋め2桁で取り出すためstrftimeを利用している df_datetime = pd.to_datetime(df_receipt['sales_epoch'], unit='s').rename('sales_month') pd.concat([df_receipt[['receipt_no', 'receipt_sub_no']], df_datetime.dt.strftime('%m')],axis=1).head(10)
code_generation
49
MIT
datascience_100_knocks_python
pandasを用いてレシート明細データ(df_receipt)の売上エポック秒(sales_epoch)を日付型に変換し、「月」だけ取り出してレシート番号(receipt_no)、レシートサブ番号(receipt_sub_no)とともに10件表示せよ。なお、「月」は0埋め2桁で取り出すこと。
import pandas as pd # dt.dayでも日を取得できるが、ここでは0埋め2桁で取り出すためstrftimeを利用している df_datetime = pd.to_datetime(df_receipt['sales_epoch'], unit='s').rename('sales_day') pd.concat([df_receipt[['receipt_no', 'receipt_sub_no']], df_datetime.dt.strftime('%d')], axis=1).head(10)
code_generation
50
MIT
datascience_100_knocks_python
pandasを用いてレシート明細データ(df_receipt)の売上エポック秒を日付型に変換し、「日」だけ取り出してレシート番号(receipt_no)、レシートサブ番号(receipt_sub_no)とともに10件表示せよ。なお、「日」は0埋め2桁で取り出すこと。
import pandas as pd # コード例1 df_sales_amount = df_receipt.query('not customer_id.str.startswith("Z")', engine='python') df_sales_amount = df_sales_amount[['customer_id', 'amount']]. \ groupby('customer_id').sum().reset_index() df_sales_amount['sales_flg'] = df_sales_amount['amount']. \ apply(lambda x: 1 if x > 2000 else 0) df_sales_amount.head(10) # コード例2(np.whereの活用) df_sales_amount = df_receipt.query('not customer_id.str.startswith("Z")', engine='python') df_sales_amount = df_sales_amount[['customer_id', 'amount']]. \ groupby('customer_id').sum().reset_index() df_sales_amount['sales_flg'] = np.where(df_sales_amount['amount'] > 2000, 1, 0) df_sales_amount.head(10)
code_generation
51
MIT
datascience_100_knocks_python
pandasを用いてレシート明細データ(df_receipt)の売上金額(amount)を顧客ID(customer_id)ごとに合計の上、売上金額合計に対して2,000円以下を0、2,000円より大きい金額を1に二値化し、顧客ID、売上金額合計とともに10件表示せよ。ただし、顧客IDが"Z"から始まるのものは非会員を表すため、除外して計算すること。
import pandas as pd # コード例1 df_tmp = df_customer[['customer_id', 'postal_cd']].copy() df_tmp['postal_flg'] = df_tmp['postal_cd']. \ apply(lambda x: 1 if 100 <= int(x[0:3]) <= 209 else 0) pd.merge(df_tmp, df_receipt, how='inner', on='customer_id'). \ groupby('postal_flg').agg({'customer_id':'nunique'}) # コード例2(np.where、betweenの活用) df_tmp = df_customer[['customer_id', 'postal_cd']].copy() df_tmp['postal_flg'] = np.where(df_tmp['postal_cd'].str[0:3].astype(int) .between(100, 209), 1, 0) pd.merge(df_tmp, df_receipt, how='inner', on='customer_id'). \ groupby('postal_flg').agg({'customer_id':'nunique'})
code_generation
52
MIT
datascience_100_knocks_python
pandasを用いて顧客データ(df_customer)の郵便番号(postal_cd)に対し、東京(先頭3桁が100〜209のもの)を1、それ以外のものを0に二値化せよ。さらにレシート明細データ(df_receipt)と結合し、全期間において売上実績のある顧客数を、作成した二値ごとにカウントせよ。
import pandas as pd # コード例1(固定で切り出す) df_customer_tmp = df_customer[['customer_id', 'address']].copy() df_customer_tmp['prefecture_cd'] = \ df_customer['address'].str[0:3].map({'埼玉県': '11', '千葉県':'12', '東京都':'13', '神奈川':'14'}) df_customer_tmp.head(10) # コード例2(正規表現を使う) df_customer_tmp = df_customer[['customer_id', 'address']].copy() df_customer_tmp['prefecture_cd'] = \ df_customer['address'].str.extract(r'(^.*?[都道府県])')[0].\ map({'埼玉県': '11', '千葉県':'12', '東京都':'13', '神奈川県':'14'}) df_customer_tmp.head(10)
code_generation
53
MIT
datascience_100_knocks_python
pandasを用いて顧客データ(df_customer)の住所(address)は、埼玉県、千葉県、東京都、神奈川県のいずれかとなっている。都道府県毎にコード値を作成し、顧客ID、住所とともに10件表示せよ。値は埼玉県を11、千葉県を12、東京都を13、神奈川県を14とすること。
import pandas as pd # コード例1 df_sales_amount = df_receipt[['customer_id', 'amount']]. \ groupby('customer_id').sum().reset_index() pct25 = np.quantile(df_sales_amount['amount'], 0.25) pct50 = np.quantile(df_sales_amount['amount'], 0.5) pct75 = np.quantile(df_sales_amount['amount'], 0.75) def pct_group(x): if x < pct25: return 1 elif pct25 <= x < pct50: return 2 elif pct50 <= x < pct75: return 3 elif pct75 <= x: return 4 df_sales_amount['pct_group'] = df_sales_amount['amount'].apply(pct_group) df_sales_amount.head(10) # 確認用コード print('pct25:', pct25) print('pct50:', pct50) print('pct75:', pct75) # コード例2(cutを使った例、四分位範囲も参考までに追加表示) df_temp = df_receipt[['customer_id', 'amount']]. \ groupby('customer_id').sum().reset_index() pct25 = np.quantile(df_sales_amount['amount'], 0.25) pct50 = np.quantile(df_sales_amount['amount'], 0.5) pct75 = np.quantile(df_sales_amount['amount'], 0.75) pct_max = df_sales_amount['amount'].max() df_temp['quantile'] = pd.cut(df_sales_amount['amount'],[0.0, pct25, pct50, pct75,pct_max+0.1], right=False) df_temp['pct_group'] = df_temp.groupby('quantile').ngroup() + 1 df_temp.head(10) # 参考コード(qcutを使った例、境界値の含む/含まないが逆になっており題意を満たさないが参考までに記載) df_temp = df_receipt.groupby('customer_id')[['amount']].sum() df_temp['quantile'], bins = \ pd.qcut(df_receipt.groupby('customer_id')['amount'].sum(), 4, retbins=True) df_temp['pct_group'] = df_temp.groupby('quantile').ngroup() + 1 df_temp.reset_index(inplace=True) display(df_temp.head(10)) print('quantiles:', bins)
code_generation
54
MIT
datascience_100_knocks_python
pandasを用いてレシート明細(df_receipt)データの売上金額(amount)を顧客ID(customer_id)ごとに合計し、その合計金額の四分位点を求めよ。その上で、顧客ごとの売上金額合計に対して以下の基準でカテゴリ値を作成し、顧客ID、売上金額合計とともに10件表示せよ。カテゴリ値は順に1〜4とする。 最小値以上第1四分位未満 ・・・ 1を付与 第1四分位以上第2四分位未満 ・・・ 2を付与 第2四分位以上第3四分位未満 ・・・ 3を付与 第3四分位以上 ・・・ 4を付与
import pandas as pd # コード例1 df_customer_era = df_customer[['customer_id', 'birth_day']].copy() df_customer_era['era'] = df_customer['age']. \ apply(lambda x: min(math.floor(x / 10) * 10, 60)) df_customer_era.head(10) # コード例2(cutの例、カテゴリは範囲で出力) df_customer_era = df_customer[['customer_id', 'birth_day']].copy() df_customer_era['era'] = pd.cut(df_customer['age'], bins=[0, 10, 20, 30, 40, 50, 60, np.inf], right=False) df_customer_era[['customer_id', 'birth_day', 'era']].head(10)
code_generation
55
MIT
datascience_100_knocks_python
pandasを用いて顧客データ(df_customer)の年齢(age)をもとに10歳刻みで年代を算出し、顧客ID(customer_id)、生年月日(birth_day)とともに10件表示せよ。ただし、60歳以上は全て60歳代とすること。年代を表すカテゴリ名は任意とする。
import pandas as pd # 性別コード1桁と年代コード2桁を連結した性年代コードを生成する df_customer_era = df_customer[['customer_id', 'birth_day']].copy() df_customer_era['era'] = df_customer['age']. \ apply(lambda x: min(math.floor(x / 10) * 10, 60)) df_customer_era['gender_era'] = \ df_customer['gender_cd'] + df_customer_era['era'].astype('str').str.zfill(2) df_customer_era.head(10)
code_generation
56
MIT
datascience_100_knocks_python
pandasを用いて性別コード(gender_cd)により、新たに性別×年代の組み合わせを表すカテゴリデータを作成し、10件表示せよ。組み合わせを表すカテゴリの値は任意とする。
import pandas as pd # コード例1(すべてのコード値を項目化) pd.get_dummies(df_customer[['customer_id', 'gender_cd']], columns=['gender_cd']).head(10) # コード例2(項目を一つ削ったり区切り文字を変えたりできる) pd.get_dummies(df_customer[['customer_id', 'gender_cd']], columns=['gender_cd'], drop_first=True, prefix='gen', prefix_sep='#').head(10)
code_generation
57
MIT
datascience_100_knocks_python
pandasを用いて顧客データ(df_customer)の性別コード(gender_cd)をダミー変数化し、顧客ID(customer_id)とともに10件表示せよ。
import pandas as pd # skleanのpreprocessing.scaleを利用するため、データの標準偏差で計算されている df_sales_amount = df_receipt.query('not customer_id.str.startswith("Z")', engine='python'). \ groupby('customer_id'). \ agg({'amount':'sum'}).reset_index() df_sales_amount['std_amount'] = preprocessing.scale(df_sales_amount['amount']) df_sales_amount.head(10) # コード例2(fitを行うことで、別のデータでも同じ平均・標準偏差で標準化を行える) df_sales_amount = df_receipt.query('not customer_id.str.startswith("Z")', engine='python'). \ groupby('customer_id'). \ agg({'amount':'sum'}).reset_index() scaler = preprocessing.StandardScaler() scaler.fit(df_sales_amount[['amount']]) df_sales_amount['std_amount'] = scaler.transform(df_sales_amount[['amount']]) df_sales_amount.head(10) TIPS: query()の引数engineで'python'か'numexpr'かを選択でき、デフォルトはインストールされていればnumexprが、無ければpythonが使われます。さらに、文字列メソッドはengine='python'でないとquery()内で使えません。
code_generation
58
MIT
datascience_100_knocks_python
pandasを用いてレシート明細データ(df_receipt)の売上金額(amount)を顧客ID(customer_id)ごとに合計し、売上金額合計を平均0、標準偏差1に標準化して顧客ID、売上金額合計とともに10件表示せよ。標準化に使用する標準偏差は、分散の平方根、もしくは不偏分散の平方根のどちらでも良いものとする。ただし、顧客IDが"Z"から始まるのものは非会員を表すため、除外して計算すること。
import pandas as pd # コード例1 df_sales_amount = df_receipt.query('not customer_id.str.startswith("Z")', engine='python'). \ groupby('customer_id'). \ agg({'amount':'sum'}).reset_index() df_sales_amount['scale_amount'] = \ preprocessing.minmax_scale(df_sales_amount['amount']) df_sales_amount.head(10) # コード例2(fitを行うことで、別のデータでも同じ最小値・最大値で標準化を行える) df_sales_amount = df_receipt.query('not customer_id.str.startswith("Z")', engine='python'). \ groupby('customer_id'). \ agg({'amount':'sum'}).reset_index() scaler = preprocessing.MinMaxScaler() scaler.fit(df_sales_amount[['amount']]) df_sales_amount['scale_amount'] = scaler.transform(df_sales_amount[['amount']]) df_sales_amount.head(10)
code_generation
59
MIT
datascience_100_knocks_python
pandasを用いてレシート明細データ(df_receipt)の売上金額(amount)を顧客ID(customer_id)ごとに合計し、売上金額合計を最小値0、最大値1に正規化して顧客ID、売上金額合計とともに10件表示せよ。ただし、顧客IDが"Z"から始まるのものは非会員を表すため、除外して計算すること。
import pandas as pd df_sales_amount = df_receipt.query('not customer_id.str.startswith("Z")', engine='python'). \ groupby('customer_id'). \ agg({'amount':'sum'}).reset_index() df_sales_amount['log_amount'] = np.log10(df_sales_amount['amount'] + 0.5) df_sales_amount.head(10)
code_generation
60
MIT
datascience_100_knocks_python
pandasを用いてレシート明細データ(df_receipt)の売上金額(amount)を顧客ID(customer_id)ごとに合計し、売上金額合計を常用対数化(底10)して顧客ID、売上金額合計とともに10件表示せよ。ただし、顧客IDが"Z"から始まるのものは非会員を表すため、除外して計算すること。
import pandas as pd df_sales_amount = df_receipt.query('not customer_id.str.startswith("Z")', engine='python'). \ groupby('customer_id'). \ agg({'amount':'sum'}).reset_index() df_sales_amount['log_amount'] = np.log(df_sales_amount['amount'] + 0.5) df_sales_amount.head(10)
code_generation
61
MIT
datascience_100_knocks_python
pandasを用いてレシート明細データ(df_receipt)の売上金額(amount)を顧客ID(customer_id)ごとに合計し、売上金額合計を自然対数化(底e)して顧客ID、売上金額合計とともに10件表示せよ。ただし、顧客IDが"Z"から始まるのものは非会員を表すため、除外して計算すること。
import pandas as pd df_tmp = df_product.copy() df_tmp['unit_profit'] = df_tmp['unit_price'] - df_tmp['unit_cost'] df_tmp.head(10)
code_generation
62
MIT
datascience_100_knocks_python
pandasを用いて商品データ(df_product)の単価(unit_price)と原価(unit_cost)から各商品の利益額を算出し、結果を10件表示せよ。
import pandas as pd df_tmp = df_product.copy() df_tmp['unit_profit_rate'] = \ (df_tmp['unit_price'] - df_tmp['unit_cost']) / df_tmp['unit_price'] df_tmp['unit_profit_rate'].mean(skipna=True)
code_generation
63
MIT
datascience_100_knocks_python
pandasを用いて商品データ(df_product)の単価(unit_price)と原価(unit_cost)から、各商品の利益率の全体平均を算出せよ。ただし、単価と原価には欠損が生じていることに注意せよ。
import pandas as pd df_tmp = df_product[['product_cd', 'unit_price', 'unit_cost']].copy() df_tmp['new_price'] = np.floor(df_tmp['unit_cost'] / 0.7) df_tmp['new_profit_rate'] = \ (df_tmp['new_price'] - df_tmp['unit_cost']) / df_tmp['new_price'] df_tmp.head(10)
code_generation
64
MIT
datascience_100_knocks_python
pandasを用いて商品データ(df_product)の各商品について、利益率が30%となる新たな単価を求めよ。ただし、1円未満は切り捨てること。そして結果を10件表示させ、利益率がおよそ30%付近であることを確認せよ。ただし、単価(unit_price)と原価(unit_cost)には欠損が生じていることに注意せよ。
import pandas as pd df_tmp = df_product[['product_cd', 'unit_price', 'unit_cost']].copy() df_tmp['new_price'] = np.round(df_tmp['unit_cost'] / 0.7) df_tmp['new_profit_rate'] = \ (df_tmp['new_price'] - df_tmp['unit_cost']) / df_tmp['new_price'] df_tmp.head(10)
code_generation
65
MIT
datascience_100_knocks_python
pandasを用いて商品データ(df_product)の各商品について、利益率が30%となる新たな単価を求めよ。今回は、1円未満を丸めること(四捨五入または偶数への丸めで良い)。そして結果を10件表示させ、利益率がおよそ30%付近であることを確認せよ。ただし、単価(unit_price)と原価(unit_cost)には欠損が生じていることに注意せよ。
import pandas as pd df_tmp = df_product[['product_cd', 'unit_price', 'unit_cost']].copy() df_tmp['new_price'] = np.ceil(df_tmp['unit_cost'] / 0.7) df_tmp['new_profit_rate'] = \ (df_tmp['new_price'] - df_tmp['unit_cost']) / df_tmp['new_price'] df_tmp.head(10)
code_generation
66
MIT
datascience_100_knocks_python
pandasを用いて商品データ(df_product)の各商品について、利益率が30%となる新たな単価を求めよ。今回は、1円未満を切り上げること。そして結果を10件表示させ、利益率がおよそ30%付近であることを確認せよ。ただし、単価(unit_price)と原価(unit_cost)には欠損が生じていることに注意せよ。
import pandas as pd df_tmp = df_tmp = df_product[['product_cd', 'unit_price']].copy() df_tmp['tax_price'] = np.floor(df_tmp['unit_price'] * 1.1) df_tmp.head(10)
code_generation
67
MIT
datascience_100_knocks_python
pandasを用いて商品データ(df_product)の各商品について、消費税率10%の税込み金額を求めよ。1円未満の端数は切り捨てとし、結果を10件表示せよ。ただし、単価(unit_price)には欠損が生じていることに注意せよ。
import pandas as pd # コード例1 df_tmp_1 = df_receipt.groupby('customer_id').agg({'amount':'sum'}). \ reset_index().rename(columns={'amount':'sum_all'}) df_tmp_2 = pd.merge(df_receipt, df_product.query('category_major_cd == "07"'), how='inner', on='product_cd').groupby('customer_id').\ agg({'amount':'sum'}).reset_index().\ rename(columns={'amount':'sum_07'}) df_tmp_3 = pd.merge(df_tmp_1, df_tmp_2, how='inner', on='customer_id') df_tmp_3['sales_rate'] = df_tmp_3['sum_07'] / df_tmp_3['sum_all'] df_tmp_3.head(10) # コード例2(参考、unstackと横方向のsumを使った例) df_temp = df_receipt.merge(df_product, how='left', on='product_cd'). \ groupby(['customer_id', 'category_major_cd'])['amount'].sum().unstack() df_temp = df_temp[df_temp['07'] > 0] df_temp['sum_all'] = df_temp.sum(axis=1) df_temp['sales_rate'] = df_temp['07'] / df_temp['sum_all'] # 以降はデータフレームの整形と表示のための処理 df_temp.columns.name = '' df_temp = df_temp.reset_index() df_temp.head(10)
code_generation
68
MIT
datascience_100_knocks_python
pandasを用いてレシート明細データ(df_receipt)と商品データ(df_product)を結合し、顧客毎に全商品の売上金額合計と、カテゴリ大区分コード(category_major_cd)が"07"(瓶詰缶詰)の売上金額合計を計算の上、両者の比率を求めよ。抽出対象はカテゴリ大区分コード"07"(瓶詰缶詰)の売上実績がある顧客のみとし、結果を10件表示せよ。
import pandas as pd df_tmp = df_receipt[['customer_id', 'sales_ymd']].drop_duplicates() df_tmp = pd.merge(df_tmp, df_customer[['customer_id', 'application_date']], how='inner', on='customer_id') df_tmp['sales_ymd'] = pd.to_datetime(df_tmp['sales_ymd'].astype('str')) df_tmp['application_date'] = pd.to_datetime(df_tmp['application_date']) df_tmp['elapsed_days'] = df_tmp['sales_ymd'] - df_tmp['application_date'] df_tmp['elapsed_days'] = df_tmp['elapsed_days'].dt.days df_tmp.head(10)
code_generation
69
MIT
datascience_100_knocks_python
pandasを用いてレシート明細データ(df_receipt)の売上日(sales_ymd)に対し、顧客データ(df_customer)の会員申込日(application_date)からの経過日数を計算し、顧客ID(customer_id)、売上日、会員申込日とともに10件表示せよ(sales_ymdは数値、application_dateは文字列でデータを保持している点に注意)。
import pandas as pd df_tmp = df_receipt[['customer_id', 'sales_ymd']].drop_duplicates() df_tmp = pd.merge(df_tmp, df_customer[['customer_id', 'application_date']], how='inner', on='customer_id') df_tmp['sales_ymd'] = pd.to_datetime(df_tmp['sales_ymd'].astype('str')) df_tmp['application_date'] = pd.to_datetime(df_tmp['application_date']) df_tmp['elapsed_months'] = df_tmp[['sales_ymd', 'application_date']]. \ apply(lambda x: relativedelta(x[0], x[1]).years * 12 + \ relativedelta(x[0], x[1]).months, axis=1) df_tmp.head(10)
code_generation
70
MIT
datascience_100_knocks_python
pandasを用いてレシート明細データ(df_receipt)の売上日(sales_ymd)に対し、顧客データ(df_customer)の会員申込日(application_date)からの経過月数を計算し、顧客ID(customer_id)、売上日、会員申込日とともに10件表示せよ(sales_ymdは数値、application_dateは文字列でデータを保持している点に注意)。1ヶ月未満は切り捨てること。
import pandas as pd df_tmp = df_receipt[['customer_id', 'sales_ymd']].drop_duplicates() df_tmp = pd.merge(df_tmp, df_customer[['customer_id', 'application_date']], how='inner', on='customer_id') df_tmp['sales_ymd'] = pd.to_datetime(df_tmp['sales_ymd'].astype('str')) df_tmp['application_date'] = pd.to_datetime(df_tmp['application_date']) df_tmp['elapsed_years'] = df_tmp[['sales_ymd', 'application_date']]. \ apply(lambda x: relativedelta(x[0], x[1]).years, axis=1) df_tmp.head(10)
code_generation
71
MIT
datascience_100_knocks_python
pandasを用いてレシート明細データ(df_receipt)の売上日(df_customer)に対し、顧客データ(df_customer)の会員申込日(application_date)からの経過年数を計算し、顧客ID(customer_id)、売上日、会員申込日とともに10件表示せよ(sales_ymdは数値、application_dateは文字列でデータを保持している点に注意)。1年未満は切り捨てること。
import pandas as pd df_tmp = df_receipt[['customer_id', 'sales_ymd']].drop_duplicates() df_tmp = pd.merge(df_tmp, df_customer[['customer_id', 'application_date']], how='inner', on='customer_id') df_tmp['sales_ymd'] = pd.to_datetime(df_tmp['sales_ymd'].astype('str')) df_tmp['application_date'] = pd.to_datetime(df_tmp['application_date']) df_tmp['elapsed_epoch'] = df_tmp['sales_ymd'].view(np.int64) - \ df_tmp['application_date'].view(np.int64) df_tmp['elapsed_epoch'] = df_tmp['elapsed_epoch'] / 10**9 df_tmp.head(10)
code_generation
72
MIT
datascience_100_knocks_python
pandasを用いてレシート明細データ(df_receipt)の売上日(sales_ymd)に対し、顧客データ(df_customer)の会員申込日(application_date)からのエポック秒による経過時間を計算し、顧客ID(customer_id)、売上日、会員申込日とともに10件表示せよ(なお、sales_ymdは数値、application_dateは文字列でデータを保持している点に注意)。なお、時間情報は保有していないため各日付は0時0分0秒を表すものとする。
import pandas as pd df_tmp = df_receipt[['sales_ymd']].copy() df_tmp['sales_ymd'] = pd.to_datetime(df_tmp['sales_ymd'].astype('str')) df_tmp['elapsed_days'] = df_tmp['sales_ymd'].apply(lambda x:x.weekday()) df_tmp['monday'] = \ df_tmp['sales_ymd'].apply(lambda x: x - relativedelta(days=x.weekday())) df_tmp.head(10)
code_generation
73
MIT
datascience_100_knocks_python
pandasを用いてレシート明細データ(df_receipt)の売上日(sales_ymd)に対し、当該週の月曜日からの経過日数を計算し、売上日、直前の月曜日付とともに10件表示せよ(sales_ymdは数値でデータを保持している点に注意)。
import pandas as pd df_customer.sample(frac=0.01).head(10)
code_generation
74
MIT
datascience_100_knocks_python
pandasを用いて顧客データ(df_customer)からランダムに1%のデータを抽出し、先頭から10件表示せよ。
import pandas as pd # sklearn.model_selection.train_test_splitを使用した例 _, df_tmp = train_test_split(df_customer, test_size=0.1, stratify=df_customer['gender_cd']) df_tmp.groupby('gender_cd').agg({'customer_id' : 'count'})
code_generation
75
MIT
datascience_100_knocks_python
pandasを用いて顧客データ(df_customer)から性別コード(gender_cd)の割合に基づきランダムに10%のデータを層化抽出し、性別コードごとに件数を集計せよ。
import pandas as pd df_sales_amount = df_receipt.groupby('customer_id'). \ agg({'amount':'sum'}).reset_index() df_sales_amount['log_sum_amount'] = np.log(df_sales_amount['amount'] + 0.5) df_sales_amount['log_sum_amount_ss'] = preprocessing.scale(df_sales_amount['log_sum_amount']) df_sales_amount.query('abs(log_sum_amount_ss) > 3').head(10)
code_generation
76
MIT
datascience_100_knocks_python
pandasを用いてレシート明細データ(df_receipt)の売上金額を顧客単位に合計し、合計した売上金額の外れ値を抽出せよ。なお、外れ値は売上金額合計を対数化したうえで平均と標準偏差を計算し、その平均から3σを超えて離れたものとする(自然対数と常用対数のどちらでも可)。結果は10件表示せよ。
import pandas as pd df_sales_amount = df_receipt.query('not customer_id.str.startswith("Z")', engine='python'). \ groupby('customer_id'). \ agg({'amount':'sum'}).reset_index() pct25 = np.percentile(df_sales_amount['amount'], q=25) pct75 = np.percentile(df_sales_amount['amount'], q=75) iqr = pct75 - pct25 amount_low = pct25 - (iqr * 1.5) amount_hight = pct75 + (iqr * 1.5) df_sales_amount.query('amount < @amount_low or @amount_hight < amount').head(10)
code_generation
77
MIT
datascience_100_knocks_python
pandasを用いてレシート明細データ(df_receipt)の売上金額(amount)を顧客単位に合計し、合計した売上金額の外れ値を抽出せよ。ただし、顧客IDが"Z"から始まるのものは非会員を表すため、除外して計算すること。なお、ここでは外れ値を第1四分位と第3四分位の差であるIQRを用いて、「第1四分位数-1.5×IQR」を下回るもの、または「第3四分位数+1.5×IQR」を超えるものとする。結果は10件表示せよ。
import pandas as pd df_product.isnull().sum()
code_generation
78
MIT
datascience_100_knocks_python
pandasを用いて商品データ(df_product)の各項目に対し、欠損数を確認せよ。
import pandas as pd df_product_1 = df_product.copy() df_product_1.dropna(inplace=True) print('削除前:', len(df_product)) print('削除後:', len(df_product_1))
code_generation
79
MIT
datascience_100_knocks_python
pandasを用いて商品データ(df_product)のいずれかの項目に欠損が発生しているレコードを全て削除した新たな商品データを作成せよ。なお、削除前後の件数を表示させ、079で確認した件数だけ減少していることも確認すること。
import pandas as pd # コード例1(Pandasのfillna) df_product_2 = df_product.fillna({ 'unit_price':np.round(np.nanmean(df_product['unit_price'])), 'unit_cost':np.round(np.nanmean(df_product['unit_cost']))}) df_product_2.isnull().sum() # コード例2(scikit-learnのSimpleImputer) imp_mean = SimpleImputer(missing_values=np.nan, strategy='mean') imp_values = imp_mean.fit_transform(df_product[['unit_price', 'unit_cost']]) df_product_2 = df_product.copy() df_product_2[['unit_price', 'unit_cost']] = imp_values.round() df_product_2.isnull().sum()
code_generation
80
MIT
datascience_100_knocks_python
pandasを用いて単価(unit_price)と原価(unit_cost)の欠損値について、それぞれの平均値で補完した新たな商品データを作成せよ。なお、平均値については1円未満を丸めること(四捨五入または偶数への丸めで良い)。補完実施後、各項目について欠損が生じていないことも確認すること。
import pandas as pd # コード例1(Pandasのfillna) df_product_3 = df_product.fillna({ 'unit_price':np.round(np.nanmedian(df_product['unit_price'])), 'unit_cost':np.round(np.nanmedian(df_product['unit_cost']))}) df_product_3.isnull().sum() # コード例2(scikit-learnのSimpleImputer) imp_mean = SimpleImputer(missing_values=np.nan, strategy='median') imp_values = imp_mean.fit_transform(df_product[['unit_price', 'unit_cost']]) df_product_3 = df_product.copy() df_product_3[['unit_price', 'unit_cost']] = imp_values.round() df_product_3.isnull().sum()
code_generation
81
MIT
datascience_100_knocks_python
pandasを用いて単価(unit_price)と原価(unit_cost)の欠損値について、それぞれの中央値で補完した新たな商品データを作成せよ。なお、中央値については1円未満を丸めること(四捨五入または偶数への丸めで良い)。補完実施後、各項目について欠損が生じていないことも確認すること。
import pandas as pd # コード例1 df_tmp = (df_product.groupby('category_small_cd') .agg(median_price=('unit_price', 'median'), median_cost=('unit_cost', 'median')).reset_index()) df_product_4 = pd.merge(df_product, df_tmp, how='inner', on='category_small_cd') df_product_4['unit_price'] = df_product_4[['unit_price', 'median_price']]. \ apply(lambda x: np.round(x[1]) if np.isnan(x[0]) else x[0], axis=1) df_product_4['unit_cost'] = df_product_4[['unit_cost', 'median_cost']]. \ apply(lambda x: np.round(x[1]) if np.isnan(x[0]) else x[0], axis=1) df_product_4.isnull().sum() # コード例2(maskの活用) df_tmp = (df_product.groupby('category_small_cd') .agg(median_price=('unit_price', 'median'), median_cost=('unit_cost', 'median')).reset_index()) df_product_4 = df_product.merge(df_tmp, how='inner', on='category_small_cd') df_product_4['unit_price'] = (df_product_4['unit_price'] .mask(df_product_4['unit_price'].isnull(), df_product_4['median_price'].round())) df_product_4['unit_cost'] = (df_product_4['unit_cost'] .mask(df_product_4['unit_cost'].isnull(), df_product_4['median_cost'].round())) df_product_4.isnull().sum() # コード例3(fillna、transformの活用) df_product_4 = df_product.copy() for x in ['unit_price', 'unit_cost']: df_product_4[x] = (df_product_4[x] .fillna(df_product_4.groupby('category_small_cd')[x] .transform('median') .round())) df_product_4.isnull().sum()
code_generation
82
MIT
datascience_100_knocks_python
pandasを用いて単価(unit_price)と原価(unit_cost)の欠損値について、各商品のカテゴリ小区分コード(category_small_cd)ごとに算出した中央値で補完した新たな商品データを作成せよ。なお、中央値については1円未満を丸めること(四捨五入または偶数への丸めで良い)。補完実施後、各項目について欠損が生じていないことも確認すること。
import pandas as pd df_receipt_2019 = df_receipt.query('20190101 <= sales_ymd <= 20191231') \ .groupby('customer_id') \ .agg(amount_2019=('amount', 'sum')) \ .reset_index() df_receipt_all = df_receipt.groupby('customer_id')\ .agg(amount_all=('amount', 'sum')) \ .reset_index() df_sales_rate = df_customer[['customer_id']] \ .merge(df_receipt_2019, how='left', on='customer_id') \ .merge(df_receipt_all, how='left', on='customer_id') df_sales_rate['amount_2019'] = df_sales_rate['amount_2019'].fillna(0) df_sales_rate['amount_all'] = df_sales_rate['amount_all'].fillna(0) df_sales_rate['amount_rate'] = \ df_sales_rate[['amount_2019','amount_all']] \ .apply(lambda x: 0 if x[0] == 0 else x[0] / x[1], axis=1) df_sales_rate['amount_rate'] = df_sales_rate['amount_rate'].fillna(0) df_sales_rate.query('amount_rate > 0').head(10)
code_generation
83
MIT
datascience_100_knocks_python
pandasを用いて顧客データ(df_customer)の全顧客に対して全期間の売上金額に占める2019年売上金額の割合を計算し、新たなデータを作成せよ。ただし、売上実績がない場合は0として扱うこと。そして計算した割合が0超のものを抽出し、結果を10件表示せよ。また、作成したデータに欠損が存在しないことを確認せよ。
import pandas as pd df_geocode_1 = df_geocode.groupby('postal_cd') \ .agg(m_longitude=('longitude', 'mean'), m_latitude=('latitude', 'mean')).reset_index() df_customer_1 = pd.merge(df_customer, df_geocode_1, how='inner', on='postal_cd') df_customer_1.head(10)
code_generation
84
MIT
datascience_100_knocks_python
pandasを用いて顧客データ(df_customer)の全顧客に対し、郵便番号(postal_cd)を用いてジオコードデータ(df_geocode)を紐付け、新たな顧客データを作成せよ。ただし、1つの郵便番号(postal_cd)に複数の経度(longitude)、緯度(latitude)情報が紐づく場合は、経度(longitude)、緯度(latitude)の平均値を算出して使用すること。また、作成結果を確認するために結果を10件表示せよ。
import pandas as pd # コード例1 def calc_distance(x1, y1, x2, y2): distance = 6371 * math.acos(math.sin(math.radians(x1)) * math.sin(math.radians(x2)) + math.cos(math.radians(x1)) * math.cos(math.radians(x2)) * math.cos(math.radians(y1) - math.radians(y2))) return distance df_tmp = pd.merge(df_customer_1, df_store, how='inner', left_on='application_store_cd', right_on='store_cd') \ .rename(columns={'address_x':'customer_address', 'address_y':'store_address'}) df_tmp['distance'] = df_tmp[['m_latitude', 'm_longitude', 'latitude', 'longitude']] \ .apply(lambda x: calc_distance(x[0], x[1], x[2], x[3]), axis=1) df_tmp[['customer_id', 'customer_address', 'store_address', 'distance']].head(10) # コード例2 def calc_distance_numpy(x1, y1, x2, y2): x1_r = np.radians(x1) x2_r = np.radians(x2) y1_r = np.radians(y1) y2_r = np.radians(y2) return 6371 * np.arccos(np.sin(x1_r) * np.sin(x2_r) + np.cos(x1_r) * np.cos(x2_r) * np.cos(y1_r - y2_r)) df_tmp = df_customer_1.merge(df_store, how='inner', left_on='application_store_cd', right_on='store_cd') \ .rename(columns={'address_x':'customer_address', 'address_y':'store_address'}) df_tmp['distance'] = calc_distance_numpy(df_tmp['m_latitude'], df_tmp['m_longitude'], df_tmp['latitude'], df_tmp['longitude']) df_tmp[['customer_id', 'customer_address', 'store_address', 'distance']].head(10)
code_generation
85
MIT
datascience_100_knocks_python
pandasを用いて緯度経度つき顧客データに対し、会員申込店舗コード(application_store_cd)をキーに店舗データ(df_store)と結合せよ。そして申込み店舗の緯度(latitude)・経度情報(longitude)と顧客住所(address)の緯度・経度を用いて申込み店舗と顧客住所の距離(単位:km)を求め、顧客ID(customer_id)、顧客住所(address)、店舗住所(address)とともに表示せよ。計算式は以下の簡易式で良いものとするが、その他精度の高い方式を利用したライブラリを利用してもかまわない。結果は10件表示せよ。 緯度(ラジアン):ϕ経度(ラジアン):λ距離L=6371∗arccos(sinϕ1∗sinϕ2cosϕ1∗cosϕ2∗cos(λ1−λ2))
import pandas as pd df_receipt_tmp = df_receipt.groupby('customer_id') \ .agg(sum_amount=('amount','sum')).reset_index() df_customer_u = pd.merge(df_customer, df_receipt_tmp, how='left', on='customer_id') df_customer_u['sum_amount'] = df_customer_u['sum_amount'].fillna(0) df_customer_u = df_customer_u.sort_values(['sum_amount', 'customer_id'], ascending=[False, True]) df_customer_u.drop_duplicates(subset=['customer_name', 'postal_cd'], keep='first', inplace=True) print('df_customer_cnt:', len(df_customer), 'df_customer_u_cnt:', len(df_customer_u), 'diff:', len(df_customer) - len(df_customer_u))
code_generation
86
MIT
datascience_100_knocks_python
pandasを用いて顧客データ(df_customer)では、異なる店舗での申込みなどにより同一顧客が複数登録されている。名前(customer_name)と郵便番号(postal_cd)が同じ顧客は同一顧客とみなして1顧客1レコードとなるように名寄せした名寄顧客データを作成し、顧客データの件数、名寄顧客データの件数、重複数を算出せよ。ただし、同一顧客に対しては売上金額合計が最も高いものを残し、売上金額合計が同一もしくは売上実績がない顧客については顧客ID(customer_id)の番号が小さいものを残すこととする。
import pandas as pd df_customer_n = pd.merge(df_customer, df_customer_u[['customer_name', 'postal_cd', 'customer_id']], how='inner', on =['customer_name', 'postal_cd']) df_customer_n.rename(columns={'customer_id_x':'customer_id', 'customer_id_y':'integration_id'}, inplace=True) print('ID数の差', len(df_customer_n['customer_id'].unique()) - len(df_customer_n['integration_id'].unique()))
code_generation
87
MIT
datascience_100_knocks_python
pandasを用いて作成したデータを元に、顧客データに統合名寄IDを付与したデータを作成せよ。ただし、統合名寄IDは以下の仕様で付与するものとする。 重複していない顧客:顧客ID(customer_id)を設定 重複している顧客:前設問で抽出したレコードの顧客IDを設定 顧客IDのユニーク件数と、統合名寄IDのユニーク件数の差も確認すること。
import pandas as pd df_sales_customer = df_receipt.groupby('customer_id') \ .agg({'amount':sum}).reset_index() df_sales_customer = df_sales_customer.query('amount > 0') df_tmp = pd.merge(df_customer, df_sales_customer['customer_id'], how='inner', on='customer_id') df_train, df_test = train_test_split(df_tmp, test_size=0.2, random_state=71) print('学習データ割合: ', len(df_train) / len(df_tmp)) print('テストデータ割合: ', len(df_test) / len(df_tmp))
code_generation
88
MIT
datascience_100_knocks_python
pandasを用いて売上実績がある顧客を、予測モデル構築のため学習用データとテスト用データに分割したい。それぞれ8:2の割合でランダムにデータを分割せよ。
import pandas as pd # コード例1(自作関数) df_ts_amount = df_receipt[['sales_ymd', 'amount']].copy() df_ts_amount['sales_ym'] = df_ts_amount['sales_ymd'].astype('str').str[0:6] df_ts_amount = df_ts_amount.groupby('sales_ym') \ .agg({'amount':'sum'}).reset_index() # 長期間データに対する多数のデータセットもループなどで処理できるように関数化 def split_data(df, train_size, test_size, slide_window, start_point): train_start = start_point * slide_window test_start = train_start + train_size return df[train_start:test_start], df[test_start:test_start + test_size] df_train_1, df_test_1 = split_data(df_ts_amount, train_size=12, test_size=6, slide_window=6, start_point=0) df_train_2, df_test_2 = split_data(df_ts_amount, train_size=12, test_size=6, slide_window=6, start_point=1) df_train_3, df_test_3 = split_data(df_ts_amount, train_size=12, test_size=6, slide_window=6, start_point=2) # df_train_2とdf_train_3の表示は割愛 df_train_1 # df_test_2とdf_test_3の表示は割愛 df_test_1 # コード例2(scikit-learnのTimeSeriesSplit) tscv = TimeSeriesSplit(gap=0, max_train_size=12, n_splits=3, test_size=6) # TimeSeriesSplitは最新のデータが使われるように分割されるが、 # SQL、Rの解答例と同じとなるようにデータ期間を調整 # できる限り最新データを使うようにするなら不要 df_ts_amount = df_ts_amount.query('sales_ym <= "201906"') series_list = [] for train_index, test_index in tscv.split(df_ts_amount): series_list.append((df_ts_amount.loc[train_index], df_ts_amount.loc[test_index])) df_train_1, df_test_1 = series_list[0] df_train_2, df_test_2 = series_list[1] df_train_3, df_test_3 = series_list[2] # df_train_2とdf_train_3の表示は割愛 df_train_1 # df_test_2とdf_test_3の表示は割愛 df_test_1
code_generation
89
MIT
datascience_100_knocks_python
pandasを用いてレシート明細データ(df_receipt)は2017年1月1日〜2019年10月31日までのデータを有している。売上金額(amount)を月次で集計し、学習用に12ヶ月、テスト用に6ヶ月の時系列モデル構築用データを3セット作成せよ。
import pandas as pd df_tmp = df_receipt.groupby('customer_id').agg({'amount':'sum'}).reset_index() df_tmp = pd.merge(df_customer, df_tmp, how='left', on='customer_id') df_tmp['is_buy_flag'] = np.where(df_tmp['amount'].isnull(), 0, 1) rs = RandomUnderSampler(random_state=71) df_down_sampling, _ = rs.fit_resample(df_tmp, df_tmp.is_buy_flag) print('0の件数', len(df_down_sampling.query('is_buy_flag == 0'))) print('1の件数', len(df_down_sampling.query('is_buy_flag == 1')))
code_generation
90
MIT
datascience_100_knocks_python
pandasを用いて顧客データ(df_customer)の各顧客に対し、売上実績がある顧客数と売上実績がない顧客数が1:1となるようにアンダーサンプリングで抽出せよ。
import pandas as pd df_gender_std = df_customer[['gender_cd', 'gender']].drop_duplicates() df_customer_std = df_customer.drop(columns='gender') # データの内容確認 df_customer_std.head(3) # データの内容確認 df_gender_std.head(3)
code_generation
91
MIT
datascience_100_knocks_python
pandasを用いて顧客データ(df_customer)の性別について、第三正規形へと正規化せよ。
import pandas as pd df_product_full = pd.merge(df_product, df_category[['category_small_cd', 'category_major_name', 'category_medium_name', 'category_small_name']], how = 'inner', on = 'category_small_cd') # データの内容確認 df_product_full.head(3)
code_generation
92
MIT
datascience_100_knocks_python
pandasを用いて商品データ(df_product)では各カテゴリのコード値だけを保有し、カテゴリ名は保有していない。カテゴリデータ(df_category)と組み合わせて非正規化し、カテゴリ名を保有した新たな商品データを作成せよ。
import pandas as pd # コード例1 df_product_full.to_csv('./data/P_df_product_full_UTF-8_header.csv', encoding='UTF-8', index=False) # コード例2(BOM付きでExcelの文字化けを防ぐ) df_product_full.to_csv('./data/P_df_product_full_UTF-8BOM_header.csv', encoding='utf_8_sig', index=False)
code_generation
93
MIT
datascience_100_knocks_python
pandasを用いてカテゴリ名付き商品データを以下の仕様でファイル出力せよ。 ファイル形式:csv ヘッダ有無:有り 文字エンコーディング:UTF-8 ファイル出力先:./data
import pandas as pd df_product_full.to_csv('./data/P_df_product_full_CP932_header.csv', encoding='CP932', index=False)
code_generation
94
MIT
datascience_100_knocks_python
pandasを用いてカテゴリ名付き商品データを以下の仕様でファイル出力せよ。 ファイル形式:csv ヘッダ有無:有り 文字エンコーディング:CP932 ファイル出力先:./data
import pandas as pd df_product_full.to_csv('./data/P_df_product_full_UTF-8_noh.csv', header=False, encoding='UTF-8', index=False)
code_generation
95
MIT
datascience_100_knocks_python
pandasを用いてpandasを用いてカテゴリ名付き商品データを以下の仕様でファイル出力せよ。 ファイル形式:csv ヘッダ有無:無し 文字エンコーディング:UTF-8 ファイル出力先:./data
import pandas as pd df_product_full = pd.read_csv('./data/P_df_product_full_UTF-8_header.csv', dtype={'category_major_cd':str, 'category_medium_cd':str, 'category_small_cd':str}, encoding='UTF-8') df_product_full.head(3)
code_generation
96
MIT
datascience_100_knocks_python
pandasを用いて作成した以下形式のファイルを読み込み、データを3件を表示させて正しく取り込まれていることを確認せよ。 ファイル形式:csv ヘッダ有無:有り 文字エンコーディング:UTF-8
import pandas as pd # コード例1(後から項目名をつける) df_product_full = pd.read_csv('../data/P_df_product_full_UTF-8_noh.csv', dtype={1:str, 2:str, 3:str}, encoding='UTF-8', header=None) df_product_full.columns = ['product_cd','category_major_cd', 'category_medium_cd', 'category_small_cd', 'unit_price','unit_cost','category_major_name', 'category_medium_name', 'category_small_name'] df_product_full.head(3) # コード例2(先に項目名を定義する) c_names = ['product_cd','category_major_cd','category_medium_cd', 'category_small_cd','unit_price','unit_cost', 'category_major_name','category_medium_name','category_small_name'] df_product_full = pd.read_csv('../data/P_df_product_full_UTF-8_noh.csv', names=c_names, dtype={'category_major_cd':str, 'category_medium_cd':str, 'category_small_cd':str}, encoding='UTF-8', header=None) df_product_full.head(3)
code_generation
97
MIT
datascience_100_knocks_python
pandasを用いて作成した以下形式のファイルを読み込み、データを3件を表示させて正しく取り込まれていることを確認せよ。 ファイル形式:csv ヘッダ有無:無し 文字エンコーディング:UTF-8
import pandas as pd df_product_full.to_csv('../data/P_df_product_full_UTF-8_header.tsv', sep='\t', encoding='UTF-8', index=False)
code_generation
98
MIT
datascience_100_knocks_python
pandasを用いて作成したカテゴリ名付き商品データを以下の仕様でファイル出力せよ。 ファイル形式:tsv ヘッダ有無:有り 文字エンコーディング:UTF-8 出力先:./data
import pandas as pd # コード例1(read_table) df_product_full = pd.read_table('../data/P_df_product_full_UTF-8_header.tsv', dtype={'category_major_cd':str, 'category_medium_cd':str, 'category_small_cd':str}, encoding='UTF-8') df_product_full.head(3) # コード例2(read_csv) df_product_full = pd.read_csv('../data/P_df_product_full_UTF-8_header.tsv', dtype={'category_major_cd':str, 'category_medium_cd':str, 'category_small_cd':str}, sep='\t', encoding='UTF-8') df_product_full.head(3)
code_generation
99
MIT
datascience_100_knocks_python
pandasを用いて作成した以下形式のファイルを読み込み、データを3件を表示させて正しく取り込まれていることを確認せよ。 ファイル形式:tsv ヘッダ有無:有り 文字エンコーディング:UTF-8

amenokaku-icon

Amenokaku-Code-Instruct

Update:

  • 2023/12/27
    データセットに JaxTon , プロになるJava のコードデータ 180 レコードを追加しました。

概要

  • コードに特化した5.2KのInstructionデータセットです。
  • データセットに含まれるデータは商用利用できるラインセンスが付与されたプログラミング学習コンテンツから収集、加工し作成しました(英語のコンテンツは日本語に自動翻訳し、翻訳の不自然な箇所を手動で修正)。
  • また、ライセンスが明記されていない学習コンテンツについては権利者に個別に連絡を取り、本データセットへの掲載の許諾を得ております。

データセット詳細

指示タスクの内訳としてはコード生成(code_generation)が1050レコード、コードの挙動確認(check_code_behavor)が150レコード、コードのバグ修正(code_fix)が4000レコードになります。 詳細な内訳は以下の通りになります。

source name num record licence url
データサイエンス100本ノック(構造化データ加工編)(Python解答) 100 MIT https://github.com/The-Japan-DataScientist-Society/100knocks-preprocess
データサイエンス100本ノック(構造化データ加工編)(SQL解答) 100 MIT https://github.com/rootassist/100knocks-preprocess-inSQLandPython-withColab
画像処理100本ノック 100 MIT https://github.com/ryoppippi/Gasyori100knock
言語処理100本ノック2020 100 MIT
MIT
(問題) https://github.com/nlp100/nlp100.github.io
(解答) https://github.com/upura/nlp100v2020
Python初学者のためのpandas100本ノック※ 100 AmenokakuCode Liscence https://qiita.com/kunishou/items/bd5fad9a334f4f5be51c
Python初学者のためのPolars100本ノック※ 100 AmenokakuCode Liscence https://qiita.com/kunishou/items/1386d14a136f585e504e
100 Numpy Execieses 100 MIT https://github.com/rougier/numpy-100
100 Julia Exercises 100 The Unliscence https://github.com/RoyiAvital/Julia100Exercises
自作Python100本ノック 100 AmenokakuCode Liscence https://qiita.com/ahpjop/items/373f807d68044cda1c9b
Python-for-Beginners-Solve-50-Exercises-Live 50 MIT https://github.com/garg10may/Python-for-Beginners-Solve-50-Exercises-Live
R初学者のためのtidyverse100本ノック 100 AmenokakuCode Liscence https://qiita.com/nekobo/items/cbf32a13637273f229da
JavaScript Questions 155 MIT https://github.com/lydiahallie/javascript-questions
Break-It-Fix-It 4,000 MIT https://github.com/michiyasunaga/BIFI
JaxTon 60 Apache-2.0 https://github.com/vopani/jaxton
プロになるJava 120 AmenokakuCode Liscence https://nowokay.hatenablog.com/entry/projava17exercise2
※ 私が過去に作成した学習コンテンツです。

ライセンス

個々のデータのライセンスは収集元のライセンスに従うため、データセット全体では混合ライセンスになります。 また、データ自体にライセンスが明記されておらず個別に権利者に言語モデル学習用途でデータセットへの掲載許諾を取ったデータに関しては AmenokakuCode Licence というライセンスを付与しています。このライセンスは、言語モデルでの学習用途に限り自由にデータを利用することを許可するものになります(そのため、データ自体を販売したり、配布することは認めていません)。

データセットの更新

データセットについては、商用利用可能なプログラミング学習コンテンツを見つけたら今後随時追加していきたいと思います。
もし、有益なコンテンツを見つけたり、自身で作成した学習コンテンツを提供しても良いという方がおりましたら是非ご連絡下さい。

データセット名

Amenokaku は古事記に登場する天迦久神(あめのかくのかみ)という鹿の神様の名前を参考にしました。

Github

https://github.com/kunishou/amenokaku-code-instruct

Downloads last month
32
Edit dataset card

Models trained or fine-tuned on kunishou/amenokaku-code-instruct