210204 Plotly + Pandas Practice

Pandas

1
2
import pandas as pd
df = pd.read_csv("data/time_confirmed.csv")

Table에서 Column 특정 Column 제거하기

  • 제거할 Column은 drop()을 사용해서 제거해준다.

    1
    2
    3
    4
    5
    # 제거할 column명을 column 속성을 명시해서 제거하거나
    df = df.drop(column=["Column1","Column2","Column3","Column4"]).sum().reset_index(name="total")
    # 명시하지 않고 axis=1를 추가해서 제거할 수 있다.
    df = df.drop(["Column1","Column2","Column3","Column4"], axis=1).sum().reset_index(name="total")
    # 제거된 column을 제외한 column을 기준으로 합계(sum)를 구하고 series를 data frame으로 바꿔준다. 바꾼 후에 새로 추가된 합계 column의 이름은 "total"로 지정해준다. (.reset_index("total"))
Read more

210203 Plotly + Pandas Practice

Plotly+Pandas

Pandas를 사용해서 csv파일을 읽어보는 간단한 실습을 해보았다.

1
2
3
4
# -*- coding: utf-8 -*-
import pandas as pd

read_csv = pd.read_csv("data/test.csv")

Excel sheet의 head(Column title)만 추출하기

1
print(read_csv.head())

특정 Column name에 해당하는 데이터를 출력

1
print(read_csv["Column name"])

Column name(1), Column name(2), Column name(3)에 해당하는 데이터를 출력

1
2
3
4
read_csv = read_csv[["Column name(1)", "Column name(2)", "Column name(3)"]]

# Column이름과 함께 지정한 특정 Column들의 데이터들이 출력된다.
print(read_csv)
Read more