김은지
김여진
박상규
안석우
X
df1 = pd.concat([df1, df2], axis=1)
https://seong6496.tistory.com/236
김은지
김여진
박상규
안석우
김은지
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()