이론문제

일석이조

김은지

  1. X
  2. df1 = pd.concat([df1,df2],axis=1)
  3. O
  4. X
  5. X
  6. O
  7. X
  8. O
  9. O
  10. O

김여진

  1. X
  2. pd.merge(df1, df2)
  3. O
  4. X
  5. X
  6. O
  7. X
  8. O
  9. O
  10. O

박상규

  1. X
  2. df1 = pd.concat([df1, df2], axis=1)
  3. O
  4. X
  5. X
  6. O
  7. X
  8. O
  9. O
  10. O

안석우

  1. X

  2. df1 = pd.concat([df1, df2], axis=1)

https://seong6496.tistory.com/236

사랑과우정SAI

김은지

  1. O
  2. False :
  3. subset=list/none, keep='first'/'last'/False
  4. X
  5. X

김여진

  1. O
  2. False
  3. keep 매개변수
  4. X
  5. X

박상규

  1. O
  2. False (Nan 값이 있기 때문에)
  3. subset()
  4. X
  5. X

안석우

실습문제

일석이조

실습 1차

김은지

1.
Fashion_data = [['green', 'M', 10.1, 'class_2'], 
                ['red', 'L', 13.5, 'class_1'],
                ['blue', 'XL', 15.3, 'class_2'],
                ['black', 'XXL', 18.0, 'class_1']]

df = pd.DataFrame(Fashion_data, columns = ['color', 'size', 'price', 'class_label'])
print(df

2.
def apply_discount(row):
    if row['class_label'] == 'class_1':
        return int(row['price'] / 0.6)
    elif row['class_label'] == 'class_2':
        return int(row['price'] / 0.3)
    else:
        return row['price']

df['price'] = df.apply(apply_discount, axis=1)

print(df)

3.
inventory = {'XXL':5,'XL':3,'L':2,'M':1}
df['inventory'] = df['size'].map(inventory)
df

김여진

#1
import pandas as pd
clothes_list=[{ 'color':'green','size':'M','price':10.1,'class_label':'class_2' },
     { 'color':'red','size':'L','price':13.5,'class_label':'class_1' },
    { 'color':'blue','size':'XL','price':15.3,'class_label':'class_2' },
    { 'color':'black','size':'XXL','price':18.0,'class_label':'class_1' },]
df = pd.DataFrame(clothes_list, columns = ['color', 'size', 'price', 'class_label'])
print(df)

#2
def discount_price(row):
    if row['class_label'] == 'class_1':
        return int(row['price'] / 0.6)
    elif row['class_label'] == 'class_2':
        return int(row['price'] / 0.3)
df['price'] = df.apply(discount_price, axis=1)
print(df)

#3
df['num'] = ['1', '2', '3', '5']
df

박상규

import pandas as pd

data = [['green', 'M', 10.1, 'class_2'],
        ['red', 'L', 13.5, 'class_1'],
        ['blue', 'XL', 15.3, 'class_2'],
        ['black', 'XXL', 18.0, 'class_1']]

df = pd.DataFrame(data, columns=['color', 'size', 'price', 'class_label'])

print("1번")
print(df)

def price(row):
    if row['class_label'] == 'class_1':
        return int(row['price'] / 0.6)
    elif row['class_label'] == 'class_2':
        return int(row['price'] / 0.3)
    else:
        return row['price']

df['price'] = df.apply(price, axis=1)
print("2번")
print(df)

inventory = {'XXL': 5, 'XL': 3, 'L': 2, 'M': 1}

df['inventory'] = df['size'].map(inventory)

print("3번")
print(df)

안석우

import pandas as pd

df_list = [
    ['green', 'M', 10.1, 'class_2'],
    ['red', 'L', 13.5, 'class_1'],
    ['blue', 'XL', 15.3, 'class_2'],
    ['black', 'XXL', 18.0, 'class_1']
]

column_name = ['color', 'size', 'price', 'class_label']

df = pd.DataFrame.from_records(df_list, columns = column_name)
df.head()

def reprice(x):
  if x['class_label'] == 'class_1':
    return int(x['price'] / 0.6)
  else:
    return int(x['price'] / 0.3)

df['price'] = df.apply(reprice, axis = 1)
df.head()

df['size_count'] = ['1', '2', '3', '5']
df = df[['color', 'size', 'size_count', 'price', 'class_label']]
df.head()