pandas 의 사용 방법 기록
1739 단어 pandas
df=pd.DataFrame({"name":[" "," "," "," "],'age':[15,15,27,20],'id':["001","002","003","004"]})
name age id
0 15 001
1 15 002
2 27 003
3 20 004
3. age 에 따라 그룹 크기 를 집계 합 니 다.
df.groupby("age").size()
age
15 2
20 1
27 1
4. 그룹 크기 에 열 이름 이 없 을 때 열 이름 설정
df.groupby("age").size().reset_index(name="num")
age num
0 15 2
1 20 1
2 27 1
df[df["age"]>20]
name age id
2 27 003
6. 모호 조회: str. contains (), 여러 모호 조건: ('a | b'), 이런 형식 ('a' | 'b') 은 잘못된 것 입 니 다. & 조건 이 없습니다.앞 에 추가 포함 되 지 않 음 ~;정확 한 조회: isin (), 안에 배열 형식 을 사용 합 니 다.
df["name"].str.contains(" ")
~df["name"].str.contains(" ")
df[df["name"].str.contains(" ")]
df["name"].isin([" "])
0 False
1 True
2 False
3 False
0 True
1 False
2 True
3 True
name age id
1 15 002
0 False
1 True
2 False
3 False
7. 서로 다른 값 의 수량 개 수 를 조회 합 니 다. 수량 만 조회 할 때 count () 함수 만 사용 합 니 다.
df["name"].str.contains(" ").value_counts()
False 3
True 1