Python trích xuất dữ liệu từ bảng tổng hợp excel

Kho lưu trữ này lấy một

List of columns:
Index[['survived', 'pclass', 'sex', 'age', 'sibsp', 'parch', 'fare',
       'embarked', 'class', 'who', 'adult_male', 'deck', 'embark_town',
       'alive', 'alone', 'Unnamed: 15'],
      dtype='object']

Shape of the Dataset:
[891, 16]

Data types of the Dataset:
survived         int64
pclass           int64
sex             object
age            float64
sibsp            int64
parch            int64
fare           float64
embarked        object
class           object
who             object
adult_male        bool
deck            object
embark_town     object
alive           object
alone             bool
Unnamed: 15    float64
dtype: object                                       
6 chứa Bảng tổng hợp với dữ liệu nguồn bên ngoài bị ẩn và chuyển đổi bộ đệm ẩn tổng hợp thành một tệp văn bản với các giá trị được phân tách bằng
List of columns:
Index[['survived', 'pclass', 'sex', 'age', 'sibsp', 'parch', 'fare',
       'embarked', 'class', 'who', 'adult_male', 'deck', 'embark_town',
       'alive', 'alone', 'Unnamed: 15'],
      dtype='object']

Shape of the Dataset:
[891, 16]

Data types of the Dataset:
survived         int64
pclass           int64
sex             object
age            float64
sibsp            int64
parch            int64
fare           float64
embarked        object
class           object
who             object
adult_male        bool
deck            object
embark_town     object
alive           object
alone             bool
Unnamed: 15    float64
dtype: object                                       
7. Nó tính đến các tệp quá lớn để có trong bộ nhớ và xử lý tình huống này bằng cách chia dữ liệu gốc thành các đợt
List of columns:
Index[['survived', 'pclass', 'sex', 'age', 'sibsp', 'parch', 'fare',
       'embarked', 'class', 'who', 'adult_male', 'deck', 'embark_town',
       'alive', 'alone', 'Unnamed: 15'],
      dtype='object']

Shape of the Dataset:
[891, 16]

Data types of the Dataset:
survived         int64
pclass           int64
sex             object
age            float64
sibsp            int64
parch            int64
fare           float64
embarked        object
class           object
who             object
adult_male        bool
deck            object
embark_town     object
alive           object
alone             bool
Unnamed: 15    float64
dtype: object                                       
8

Tài liệu

phương pháp luận

Mã này giải nén tệp

List of columns:
Index[['survived', 'pclass', 'sex', 'age', 'sibsp', 'parch', 'fare',
       'embarked', 'class', 'who', 'adult_male', 'deck', 'embark_town',
       'alive', 'alone', 'Unnamed: 15'],
      dtype='object']

Shape of the Dataset:
[891, 16]

Data types of the Dataset:
survived         int64
pclass           int64
sex             object
age            float64
sibsp            int64
parch            int64
fare           float64
embarked        object
class           object
who             object
adult_male        bool
deck            object
embark_town     object
alive           object
alone             bool
Unnamed: 15    float64
dtype: object                                       
9 và trích xuất dữ liệu có trong tệp
x = [1, 2, 3, 4, 5, 6, 7, 8, 9]
x[0:3]
0. Các bản ghi bộ nhớ cache của trục được phân tích cú pháp và sắp xếp thành một giá trị riêng biệt
List of columns:
Index[['survived', 'pclass', 'sex', 'age', 'sibsp', 'parch', 'fare',
       'embarked', 'class', 'who', 'adult_male', 'deck', 'embark_town',
       'alive', 'alone', 'Unnamed: 15'],
      dtype='object']

Shape of the Dataset:
[891, 16]

Data types of the Dataset:
survived         int64
pclass           int64
sex             object
age            float64
sibsp            int64
parch            int64
fare           float64
embarked        object
class           object
who             object
adult_male        bool
deck            object
embark_town     object
alive           object
alone             bool
Unnamed: 15    float64
dtype: object                                       
7

Bắt đầu

điều kiện tiên quyết

  1. con trăn 3. 6 và píp

cài đặt

  1. Sao chép dự án từ ocampor/pivot-table-to-csv
  2. Cài đặt trăn 3. 6 và píp
  3. Tạo một môi trường ảo ________ 22 và tạo nguồn cho nó ________ 23
  4. Cài đặt yêu cầu python
    x = [1, 2, 3, 4, 5, 6, 7, 8, 9]
    x[0:3]
    
    4

Mã vận hành

Bạn có thể chạy mã bằng cách thực thi

x = [1, 2, 3, 4, 5, 6, 7, 8, 9]
x[0:3]
5. Các tùy chọn như sau

  1. List of columns:
    Index[['survived', 'pclass', 'sex', 'age', 'sibsp', 'parch', 'fare',
           'embarked', 'class', 'who', 'adult_male', 'deck', 'embark_town',
           'alive', 'alone', 'Unnamed: 15'],
          dtype='object']
    
    Shape of the Dataset:
    [891, 16]
    
    Data types of the Dataset:
    survived         int64
    pclass           int64
    sex             object
    age            float64
    sibsp            int64
    parch            int64
    fare           float64
    embarked        object
    class           object
    who             object
    adult_male        bool
    deck            object
    embark_town     object
    alive           object
    alone             bool
    Unnamed: 15    float64
    dtype: object                                       
    
    70 hoặc
    List of columns:
    Index[['survived', 'pclass', 'sex', 'age', 'sibsp', 'parch', 'fare',
           'embarked', 'class', 'who', 'adult_male', 'deck', 'embark_town',
           'alive', 'alone', 'Unnamed: 15'],
          dtype='object']
    
    Shape of the Dataset:
    [891, 16]
    
    Data types of the Dataset:
    survived         int64
    pclass           int64
    sex             object
    age            float64
    sibsp            int64
    parch            int64
    fare           float64
    embarked        object
    class           object
    who             object
    adult_male        bool
    deck            object
    embark_town     object
    alive           object
    alone             bool
    Unnamed: 15    float64
    dtype: object                                       
    
    71 một tùy chọn bắt buộc chỉ định tệp cần chuyển đổi
  2. Tùy chọn tùy chọn
    List of columns:
    Index[['survived', 'pclass', 'sex', 'age', 'sibsp', 'parch', 'fare',
           'embarked', 'class', 'who', 'adult_male', 'deck', 'embark_town',
           'alive', 'alone', 'Unnamed: 15'],
          dtype='object']
    
    Shape of the Dataset:
    [891, 16]
    
    Data types of the Dataset:
    survived         int64
    pclass           int64
    sex             object
    age            float64
    sibsp            int64
    parch            int64
    fare           float64
    embarked        object
    class           object
    who             object
    adult_male        bool
    deck            object
    embark_town     object
    alive           object
    alone             bool
    Unnamed: 15    float64
    dtype: object                                       
    
    72 hoặc
    List of columns:
    Index[['survived', 'pclass', 'sex', 'age', 'sibsp', 'parch', 'fare',
           'embarked', 'class', 'who', 'adult_male', 'deck', 'embark_town',
           'alive', 'alone', 'Unnamed: 15'],
          dtype='object']
    
    Shape of the Dataset:
    [891, 16]
    
    Data types of the Dataset:
    survived         int64
    pclass           int64
    sex             object
    age            float64
    sibsp            int64
    parch            int64
    fare           float64
    embarked        object
    class           object
    who             object
    adult_male        bool
    deck            object
    embark_town     object
    alive           object
    alone             bool
    Unnamed: 15    float64
    dtype: object                                       
    
    73 chỉ định tên tệp đầu ra mong muốn
  3. List of columns:
    Index[['survived', 'pclass', 'sex', 'age', 'sibsp', 'parch', 'fare',
           'embarked', 'class', 'who', 'adult_male', 'deck', 'embark_town',
           'alive', 'alone', 'Unnamed: 15'],
          dtype='object']
    
    Shape of the Dataset:
    [891, 16]
    
    Data types of the Dataset:
    survived         int64
    pclass           int64
    sex             object
    age            float64
    sibsp            int64
    parch            int64
    fare           float64
    embarked        object
    class           object
    who             object
    adult_male        bool
    deck            object
    embark_town     object
    alive           object
    alone             bool
    Unnamed: 15    float64
    dtype: object                                       
    
    74 hoặc
    List of columns:
    Index[['survived', 'pclass', 'sex', 'age', 'sibsp', 'parch', 'fare',
           'embarked', 'class', 'who', 'adult_male', 'deck', 'embark_town',
           'alive', 'alone', 'Unnamed: 15'],
          dtype='object']
    
    Shape of the Dataset:
    [891, 16]
    
    Data types of the Dataset:
    survived         int64
    pclass           int64
    sex             object
    age            float64
    sibsp            int64
    parch            int64
    fare           float64
    embarked        object
    class           object
    who             object
    adult_male        bool
    deck            object
    embark_town     object
    alive           object
    alone             bool
    Unnamed: 15    float64
    dtype: object                                       
    
    75 số lượng hoặc phần để tách tệp gốc trước khi chuyển đổi. Nên chia nhỏ file thành 5 phần đối với file excel dung lượng 100mb. Khuyến nghị thứ hai cho thiết bị có RAM 16 gb
  4. List of columns:
    Index[['survived', 'pclass', 'sex', 'age', 'sibsp', 'parch', 'fare',
           'embarked', 'class', 'who', 'adult_male', 'deck', 'embark_town',
           'alive', 'alone', 'Unnamed: 15'],
          dtype='object']
    
    Shape of the Dataset:
    [891, 16]
    
    Data types of the Dataset:
    survived         int64
    pclass           int64
    sex             object
    age            float64
    sibsp            int64
    parch            int64
    fare           float64
    embarked        object
    class           object
    who             object
    adult_male        bool
    deck            object
    embark_town     object
    alive           object
    alone             bool
    Unnamed: 15    float64
    dtype: object                                       
    
    76 hoặc
    List of columns:
    Index[['survived', 'pclass', 'sex', 'age', 'sibsp', 'parch', 'fare',
           'embarked', 'class', 'who', 'adult_male', 'deck', 'embark_town',
           'alive', 'alone', 'Unnamed: 15'],
          dtype='object']
    
    Shape of the Dataset:
    [891, 16]
    
    Data types of the Dataset:
    survived         int64
    pclass           int64
    sex             object
    age            float64
    sibsp            int64
    parch            int64
    fare           float64
    embarked        object
    class           object
    who             object
    adult_male        bool
    deck            object
    embark_town     object
    alive           object
    alone             bool
    Unnamed: 15    float64
    dtype: object                                       
    
    77 kích hoạt mức ghi GỠ LỖI

Chạy thử nghiệm

  1. Chạy
    List of columns:
    Index[['survived', 'pclass', 'sex', 'age', 'sibsp', 'parch', 'fare',
           'embarked', 'class', 'who', 'adult_male', 'deck', 'embark_town',
           'alive', 'alone', 'Unnamed: 15'],
          dtype='object']
    
    Shape of the Dataset:
    [891, 16]
    
    Data types of the Dataset:
    survived         int64
    pclass           int64
    sex             object
    age            float64
    sibsp            int64
    parch            int64
    fare           float64
    embarked        object
    class           object
    who             object
    adult_male        bool
    deck            object
    embark_town     object
    alive           object
    alone             bool
    Unnamed: 15    float64
    dtype: object                                       
    
    78

triển khai

được bao gồm

Đóng góp

Khi đóng góp cho kho lưu trữ này, trước tiên vui lòng thảo luận về thay đổi mà bạn muốn thực hiện thông qua vấn đề, email hoặc bất kỳ phương thức nào khác với chủ sở hữu của kho lưu trữ này trước khi thực hiện thay đổi

Viết chương trình Pandas để trích xuất nhãn cột, hình dạng và kiểu dữ liệu của tập dữ liệu [titanic. csv]. Chuyển đến Trình chỉnh sửa

Giải pháp mẫu

Mã Python

import pandas as pd
import numpy as np
df = pd.read_csv['titanic.csv']
print["List of columns:"]
print[df.columns]
print["\nShape of the Dataset:"]
print[df.shape]
print["\nData types of the Dataset:"]
print[df.dtypes]

Đầu ra mẫu

List of columns:
Index[['survived', 'pclass', 'sex', 'age', 'sibsp', 'parch', 'fare',
       'embarked', 'class', 'who', 'adult_male', 'deck', 'embark_town',
       'alive', 'alone', 'Unnamed: 15'],
      dtype='object']

Shape of the Dataset:
[891, 16]

Data types of the Dataset:
survived         int64
pclass           int64
sex             object
age            float64
sibsp            int64
parch            int64
fare           float64
embarked        object
class           object
who             object
adult_male        bool
deck            object
embark_town     object
alive           object
alone             bool
Unnamed: 15    float64
dtype: object                                       

Trình chỉnh sửa mã Python

Xoay Titanic. csv


Có một cách khác để giải quyết giải pháp này?

Trước. Viết chương trình Pandas để in một bản tóm tắt ngắn gọn về tập dữ liệu [titanic. csv].
Tiếp theo. Viết chương trình Pandas để tạo bảng Pivot với nhiều chỉ mục từ tập dữ liệu của titanic. csv.

Mức độ khó của bài tập này là gì?

Dễ dàng trung bình khó

Kiểm tra kỹ năng Lập trình của bạn với bài kiểm tra của w3resource



Chia sẻ Hướng dẫn / Bài tập này trên. FacebookTwitter

con trăn. Lời khuyên trong ngày

Liệt kê các thủ thuật cắt lát

danh sách [bắt đầu. dừng lại. bươc]

x = [1, 2, 3, 4, 5, 6, 7, 8, 9]
x[0:3]

đầu ra

[1, 2, 3]
x[3:]

đầu ra

[4, 5, 6, 7, 8, 9]
x[:6]

đầu ra

[1, 2, 3, 4, 5, 6]
x[0:6:2]

đầu ra

[1, 3, 5]
List of columns:
Index[['survived', 'pclass', 'sex', 'age', 'sibsp', 'parch', 'fare',
       'embarked', 'class', 'who', 'adult_male', 'deck', 'embark_town',
       'alive', 'alone', 'Unnamed: 15'],
      dtype='object']

Shape of the Dataset:
[891, 16]

Data types of the Dataset:
survived         int64
pclass           int64
sex             object
age            float64
sibsp            int64
parch            int64
fare           float64
embarked        object
class           object
who             object
adult_male        bool
deck            object
embark_town     object
alive           object
alone             bool
Unnamed: 15    float64
dtype: object                                       
0

đầu ra

[1, 2, 3, 4, 5, 6]
List of columns:
Index[['survived', 'pclass', 'sex', 'age', 'sibsp', 'parch', 'fare',
       'embarked', 'class', 'who', 'adult_male', 'deck', 'embark_town',
       'alive', 'alone', 'Unnamed: 15'],
      dtype='object']

Shape of the Dataset:
[891, 16]

Data types of the Dataset:
survived         int64
pclass           int64
sex             object
age            float64
sibsp            int64
parch            int64
fare           float64
embarked        object
class           object
who             object
adult_male        bool
deck            object
embark_town     object
alive           object
alone             bool
Unnamed: 15    float64
dtype: object                                       
2

đầu ra

List of columns:
Index[['survived', 'pclass', 'sex', 'age', 'sibsp', 'parch', 'fare',
       'embarked', 'class', 'who', 'adult_male', 'deck', 'embark_town',
       'alive', 'alone', 'Unnamed: 15'],
      dtype='object']

Shape of the Dataset:
[891, 16]

Data types of the Dataset:
survived         int64
pclass           int64
sex             object
age            float64
sibsp            int64
parch            int64
fare           float64
embarked        object
class           object
who             object
adult_male        bool
deck            object
embark_town     object
alive           object
alone             bool
Unnamed: 15    float64
dtype: object                                       
3____14

đầu ra

List of columns:
Index[['survived', 'pclass', 'sex', 'age', 'sibsp', 'parch', 'fare',
       'embarked', 'class', 'who', 'adult_male', 'deck', 'embark_town',
       'alive', 'alone', 'Unnamed: 15'],
      dtype='object']

Shape of the Dataset:
[891, 16]

Data types of the Dataset:
survived         int64
pclass           int64
sex             object
age            float64
sibsp            int64
parch            int64
fare           float64
embarked        object
class           object
who             object
adult_male        bool
deck            object
embark_town     object
alive           object
alone             bool
Unnamed: 15    float64
dtype: object                                       
5Đang tải

  • bài tập. Top 16 chủ đề phổ biến nhất hàng tuần
  • Bài tập SQL, Thực hành, Lời giải - THAM GIA
  • Bài tập, Thực hành, Giải pháp SQL - SUBQUERIES
  • JavaScript cơ bản - Bài tập, Thực hành, Lời giải
  • Mảng Java. Bài tập, Luyện tập, Lời giải
  • Bài Tập Lập Trình C, Thực Hành, Lời Giải. Tuyên bố có điều kiện
  • Cơ sở dữ liệu nhân sự - SORT FILTER. Bài tập, Luyện tập, Lời giải
  • Bài Tập Lập Trình C, Thực Hành, Lời Giải. Sợi dây
  • Kiểu dữ liệu Python. Từ điển - Bài tập, Thực hành, Lời giải
  • Câu đố lập trình Python - Bài tập, Thực hành, Giải pháp
  • Mảng C++. Bài tập, Luyện tập, Lời giải
  • Câu lệnh điều kiện và vòng lặp JavaScript - Bài tập, Thực hành, Lời giải
  • Thuật toán cơ bản C# Sharp. Bài tập, Luyện tập, Lời giải
  • Python Lambda - Bài tập, Thực hành, Giải pháp
  • Khung dữ liệu Python Pandas. Bài tập, Luyện tập, Lời giải
  • Công cụ chuyển đổi
  • JavaScript. Xác thực biểu mẫu HTML

Python có thể lấy dữ liệu từ Excel không?

Người ta có thể truy xuất thông tin từ bảng tính . Việc đọc, viết hoặc sửa đổi dữ liệu có thể được thực hiện bằng Python có thể được thực hiện bằng các phương pháp khác nhau.

Gấu trúc có thể đọc bảng tổng hợp không?

Bảng tổng hợp là một bảng thống kê giúp tóm tắt dữ liệu của một bảng lớn hơn bằng cách “xoay vòng” dữ liệu đó. Microsoft Excel đã phổ biến bảng tổng hợp, nơi chúng được gọi là PivotTable. Pandas cấp quyền truy cập để tạo bảng tổng hợp trong Python bằng cách sử dụng. hàm Pivot_table[] .

Tôi có thể chuyển đổi bảng tổng hợp hiện có sang mô hình dữ liệu không?

Thêm dữ liệu hiện có, không liên quan vào Mô hình dữ liệu . Sử dụng một trong những cách tiếp cận này để thêm dữ liệu của bạn. Nhấp Power Pivot > Thêm vào Mô hình Dữ liệu . Bấm Chèn > PivotTable, rồi chọn Thêm dữ liệu này vào Mô hình Dữ liệu trong hộp thoại Tạo PivotTable.

Bảng tổng hợp có thể kéo các giá trị văn bản không?

Giá trị văn bản của bảng tổng hợp. Hiển thị văn bản trong khu vực Giá trị của Bảng tổng hợp, bằng cách sử dụng định dạng có điều kiện và định dạng số tùy chỉnh . Thiết lập điều này theo cách thủ công hoặc bằng macro.

Chủ Đề