■ DataFrame 클래스의 rename 메소드를 사용해 컬럼명을 변경하는 방법을 보여준다.
▶ main.py
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
import pandas as pd dataFrame = pd.read_csv("https://s3-us-west-2.amazonaws.com/streamlit-demo-data/uber-raw-data-sep14.csv.gz", nrows = 1000) print("[변경전]") print(dataFrame) print() convertToLowerCaseString = lambda x : str(x).lower() dataFrame.rename(convertToLowerCaseString, axis = "columns", inplace = True) print("[변경후]") print(dataFrame) print() """ [변경전] Date/Time Lat Lon Base 0 9/1/2014 0:01:00 40.2201 -74.0021 B02512 1 9/1/2014 0:01:00 40.7500 -74.0027 B02512 2 9/1/2014 0:03:00 40.7559 -73.9864 B02512 3 9/1/2014 0:06:00 40.7450 -73.9889 B02512 4 9/1/2014 0:11:00 40.8145 -73.9444 B02512 .. ... ... ... ... 995 9/2/2014 11:11:00 40.7381 -73.9878 B02512 996 9/2/2014 11:14:00 40.7848 -73.9560 B02512 997 9/2/2014 11:14:00 40.7848 -73.9560 B02512 998 9/2/2014 11:17:00 40.7741 -73.9608 B02512 999 9/2/2014 11:18:00 40.7410 -73.7579 B02512 [1000 rows x 4 columns] [변경후] date/time lat lon base 0 9/1/2014 0:01:00 40.2201 -74.0021 B02512 1 9/1/2014 0:01:00 40.7500 -74.0027 B02512 2 9/1/2014 0:03:00 40.7559 -73.9864 B02512 3 9/1/2014 0:06:00 40.7450 -73.9889 B02512 4 9/1/2014 0:11:00 40.8145 -73.9444 B02512 .. ... ... ... ... 995 9/2/2014 11:11:00 40.7381 -73.9878 B02512 996 9/2/2014 11:14:00 40.7848 -73.9560 B02512 997 9/2/2014 11:14:00 40.7848 -73.9560 B02512 998 9/2/2014 11:17:00 40.7741 -73.9608 B02512 999 9/2/2014 11:18:00 40.7410 -73.7579 B02512 [1000 rows x 4 columns] """ |
▶ requirements.txt
1 2 3 4 5 6 7 8 |
numpy==2.0.0 pandas==2.2.2 python-dateutil==2.9.0.post0 pytz==2024.1 six==1.16.0 tzdata==2024.1 |
※ pip install pandas 명령을 실행했다.