Notice
														
												
											
												
												
													Recent Posts
													
											
												
												
													Recent Comments
													
											
												
												
													Link
													
											
									| 일 | 월 | 화 | 수 | 목 | 금 | 토 | 
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 | 
| 9 | 10 | 11 | 12 | 13 | 14 | 15 | 
| 16 | 17 | 18 | 19 | 20 | 21 | 22 | 
| 23 | 24 | 25 | 26 | 27 | 28 | 29 | 
| 30 | 
													Tags
													
											
												
												- PER
 - MySQL
 - GIT
 - 함수
 - PyQt
 - mssql
 - PyQt5
 - IOS
 - 유니티
 - urllib
 - Unity
 - 날짜
 - sqlite
 - flutter
 - Excel
 - 맛집
 - pandas
 - Linux
 - node.js
 - ubuntu
 - ASP
 - 라즈베리파이
 - swift
 - tensorflow
 - python
 - MS-SQL
 - javascript
 - port
 - 리눅스
 - 다이어트
 
													Archives
													
											
											
											
											아미(아름다운미소)
컬럼명을 닥셔너리에 저장 후 불러쓰기 본문
1)
import pandas as pd
# 타입을 지정한 딕셔너리 생성
col_dict = {
    'first_col': 'str',
    'second_col': 'int',
    'third_col': 'float'
}
# 데이터프레임 생성
df = pd.DataFrame({
    'first_col': ['a', 'b', 'c'],
    'second_col': [1, 2, 3],
    'third_col': [1.1, 2.2, 3.3]
})
# 컬럼 타입 지정
for col, dtype in col_dict.items():
    df[col] = df[col].astype(dtype)
# 컬럼명 출력
print(list(col_dict.keys())[2])
2)
import pandas as pd
# 데이터프레임 생성
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9]})
# 컬럼명을 딕셔너리에 저장
col_dict = {
    'first_col': 'A',
    'second_col': 'B',
    'third_col': 'C'
}
# 딕셔너리의 키를 이용하여 컬럼 선택
print(df[col_dict['first_col']])
print(df[col_dict['second_col']])
print(df[col_dict['third_col']])'랭귀지 > pandas' 카테고리의 다른 글
| pandas 에서 aaa.str[:4] a가없을경우 제외하기 (0) | 2024.07.08 | 
|---|---|
| pandas 컬럼 마지막으로 이동 (0) | 2024.07.02 | 
| 데이터프레임의 컬럼 타입을 지정된 타입으로 변경 (0) | 2024.06.28 | 
| pandas 병렬처리 (0) | 2024.06.27 | 
| 타입지정 (0) | 2024.06.26 | 
			  Comments