본문 바로가기

전체 글100

[django] 관리자 계정 오류 django.db.utils.OperationalError: no such table: auth_user 이 에러는 auth_user table이 없어서 발생되는 에러이기 때문에 아래 코드를 통해서 테이블을 만들기 위해 사용되는 migration을 해주기! % python3 manage.py makemigrations % python3 manage.py migrate 위 코드를 하면 admin.py 파일이 생성되고 다시 % python manage.py createsuperuser 하면 username 생성할 것임! 2023. 7. 6.
가상머신(virtual environment)에 리눅스 깔기 맥 버전 1. https://www.virtualbox.org/ 2. download 3. windows host 다운로드 하기 4. 다운받은 ubuntu.org import 해오기 2023. 7. 4.
[Python] Virtual Environment 만드는 방법 pip 설치/업그레이드 python3 -m pip install --user --upgrade pip python3 -m pip --version pip 21.1.3 from $HOME/.local/lib/python3.9/site-packages (python 3.9) 버츄얼 환경 설치 python3 -m pip install --user virtualenv 버츄얼 환경 활성화 시키기 python3 -m venv env source env/bin/activate which python 버츄얼 환경 종료 deactivate 패키지 설치 python3 -m pip install requests Collecting requests Using cached requests-2.18.4-py2.py3-none-a.. 2023. 6. 17.
[python] data cleaning in pandas import pandas as pd In [40]: df= pd.read_excel(f'/Users/grace/Desktop/Alex/Customer Call List.xlsx') df #중복 제거 df.drop_duplicates() df #마지막 컬럼 제거 df= df.drop(columns = 'Not_Useful_Column') df # 1. numeric 으로 다 만들기 using replace # replace anything with empty string to nothing '[a-zA-Z0-9]' 해서 assign 한다음에 # we need to change every thing into string first # then use lambda to make it as 000-000-000.. 2023. 6. 1.
[python] visualization pandas import pandas as pd import numpy as np import matplotlib.pyplot as plt In [37]: #불러오기 df = pd.read_csv(f'/Users/grace/Desktop/Alex/Ice Cream Ratings.csv') df Out[37]: DateFlavor RatingTexture RatingOverall Rating0123456 1/1/2022 0.223090 0.040220 0.600129 1/2/2022 0.635886 0.938476 0.106264 1/3/2022 0.442323 0.044154 0.598112 1/4/2022 0.389128 0.549676 0.489353 1/5/2022 0.386887 0.519439 0.98828.. 2023. 6. 1.
[python] merge, join, concatenate pandas import pandas as pd In [3]: #df1 생성하기 df1 = pd.read_csv(f'/Users/grace/Desktop/Alex/LOTR.csv') df1 Out[3]: FellowshipIDFirstNameSkills0123 1001 Frodo Hiding 1002 Samwise Gardening 1003 Gandalf Spells 1004 Pippin Fireworks #df2 생성하기 df2 = pd.read_csv(r"/Users/grace/Desktop/Alex/LOTR 2.csv") df2 Out[5]: FellowshipIDFirstNameAge01234 1001 Frodo 50 1002 Samwise 39 1006 Legolas 2931 1007 Elrond 6520 .. 2023. 6. 1.
[python] pandas group by and agg. function Group by and Aggregating In [1]: import pandas as pd df = pd.read_csv(f'/Users/grace/Desktop/Alex/Flavors.csv') df #group_by_frame = base flavor로 그룹짓기 group_by_frame= df.groupby('Base Flavor') #mean 구하기 group_by_frame.mean() #base flavor만 뽑아서 횟수 세기 group_by_frame.count() #base flavor만 뽑아서 sum group_by_frame.sum() - .agg에는 dictionary가 필요함 #base flavor만 뽑아서 Flavor Rating이랑 Texture Rating의 ['mean',.. 2023. 6. 1.
[python] pandas indexes import pandas as pd In [3]: #csv 불러오기 df = pd.read_csv(f'/Users/grace/Desktop/Alex/world_population.csv') df #csv 불러오기 - Country로 인덱스 잡기 df = pd.read_csv(f'/Users/grace/Desktop/Alex/world_population.csv',index_col='Country') df - reset_index(inplace = True ) 다른 변수에 저장하지 않는 다는 뜻 #인덱스 다시 reset하기 df.reset_index(inplace=True) df - 재설정한 index를 save 하고 싶으면 Inplace = True 를 꼭 넣어줘야 함 #'Country'를 index다시.. 2023. 6. 1.
[python] Pandas Filtering and Ordering 주피터 노트북을 사용해서 filtering 과 ordering 사용 1. import pandas import import pandas as pd 2. csv 파일 불러오기 In [2]:3. #폴더에서 데이터 불러오기 df = pd.read_csv(f'/Users/grace/Desktop/Alex/world_population.csv') df df[df['Rank'] 컬럼을 찾고 싶으면 axis 1 추가 필요) #'Continent','CCA3'만 filter하는 테이블 만들기(item, axis 사용) df2.filter(items = ['Continent','CCA3'], axis = 1) Out[26]: - axis = 0 (가로 행에서의 정보를 찾을 때) #'Zimbabwe'만 filter하는 테.. 2023. 5. 31.