python dictionary unpacking의 모든 것(딕셔너리 unpacking, merge, 병합)
1. Passing Dictionary to a Functiondef introduce(name, age, city): print(f"이름: {name}, 나이: {age}, 도시: {city}")person = {"name": "John", "age": 25, "city": "New York"}# Unpack dictionary into function argumentsintroduce(**person)"""Name: John, Age: 25, City: New York""" 2. Merging Dictionaries dict_a = {"a": 1, "b": 2}dict_b = {"c": 3, "d": 4}merged = {**dict_a, **dict_b}print(merged)"""{'a'..
2025. 8. 22.
explode의 이해: Pandas dataframe에서 list 원소를 펼치는 방법
데이터프레임 전처리를 하다 보면, 가끔 아래처럼 grade별로 number가 list로 묶여있는 데이터를 마주하게 된다.data = {'grade': [1, 2, 3], 'number': [[10, 20], [30], [40, 50, 60]]}df = pd.DataFrame(data)### grade number0 1 [10, 20]1 2 [30]2 3 [40, 50, 60]### 이런 경험이 없으면, long form으로 쫙 펼쳐서 보고 싶은데 참 난감하다. 이 경우 pandas에서는 어떻게 쉽게 해결할 수 있는지, 그리고 그것을 구현해 보는 시간을 갖도록 한다.(직접 해보는 이유는, 단순히 method 하나 들고와서 "띡" 해결하는 것이 아닌 처리 로직을 이해하기 위함이다.) 1. ..
2025. 3. 9.