回覆列表
  • 1 # 風控小姐姐一一

    ```

    # 透過 list of list 建立 DataFrame

    import pandas as pd

    data = [["Apple", 6], ["Grape", 30], ["Banana", 5]]

    df = pd.DataFrame(data, columns = ["Fruit", "Price"])

    df

    # 透過 dict of list 建立 DataFrame

    import pandas as pd

    data = {"Fruit":["Apple", "Grape", "Banana"], "Price":[6, 30, 5]}

    df = pd.DataFrame(data)

    df

    # 透過 list of dicts 建立 DataFrame

    import pandas as pd

    data = [{"Fruit": "Apple", "Price": 6}, {"Fruit": "Grape", "Price": 30}, {"Fruit": "Banana", "Price": 5}]

    df = pd.DataFrame(data)

    df

    # 透過 zip() 函式建立 DataFrame

    import pandas as pd

    Fruit = ["Apple", "Grape", "Banana"]

    Price = [6, 30, 5]

    list_of_tuples = list(zip(Fruit, Price))

    df = pd.DataFrame(list_of_tuples, columns = ["Name", "Age"])

    df

    # 新建空的 DataFrame,逐行新增資料

    import pandas as pd

    df = pd.DataFrame(columns = ["Fruit", "Price"])

    df = df.append({"Fruit": "Apple", "Price": 6}, ignore_index=True)

    df = df.append({"Fruit": "Grape", "Price": 30}, ignore_index=True)

    df = df.append({"Fruit": "Banana", "Price": 5}, ignore_index=True)

    df

    ```

  • 中秋節和大豐收的關聯?
  • 《青青園中葵,朝露待日晞.》的意思?