라이브러리 및 데이터 불러오기
import numpy as np
import pandas as pd
Numpy
items = np.array([[20, 12.34, True, "A"],
[12, 34.1, False, "B"],
[43, 55.3, True, "A"],
[45, 64.2, False, "C"],
[23, 65.1, False, "E"],
[65, 22.3, True, "A"],
[9, 44.1, True, "B"],
[122, 67.1, False, "C"],
[567, 34.2, False, "C"]], dtype=object)
items
items.shape
new_items = items.reshape((1,36))
print("shape:", new_items.shape)
print("*" * 10)
new_items
items = items.transpose()
print("shape:", items.shape)
print("*" * 10)
items
min(items[0]), max(items[0])
Pandas
df = pd.DataFrame([{"a": 20, "b": 12.34, "c": True, "d": "A"},
{"a": 12, "b": 34.1, "c": False, "d": "B"},
{"a": 43, "b": 55.3, "c": True, "d": "A"},
{"a": 45, "b": 64.2, "c": False, "d": "C"},
{"a": 23, "b": 65.1, "c": False, "d": "E"},
{"a": 65, "b": 22.3, "c": True, "d": "A"},
{"a": 9, "b": 44.1, "c": True, "d": "B"},
{"a": 122, "b": 67.1, "c": False, "d": "C"},
{"a": 567, "b": 34.2, "c": False, "d": "C"},])
df
df.info()
df.describe()
df.index
df.columns
df.iloc[:, :-1]
value = df['a']
print("type:", type(value))
print("*" * 10)
value
value = df[['a']]
print("type:", type(value))
print("*" * 10)
value
value = df[['a', 'c']]
print("type:", type(value))
print("*" * 10)
value
df['d'].unique()
df[['d']].value_counts()
df[df['b'] > 50]
new_data = ["hello", "bye", "nice", "good", "apple", "banana", "tomato", "keyboard", "mouse"]
pd.concat([df, pd.DataFrame(new_data, columns=['e'])], axis=1)
new_data = {"a": 73, "b": 65.1, "c": True, "d": "B"}
pd.concat([df, pd.DataFrame([new_data])], axis=0)