Hướng dẫn data cleaning projects in python github - dự án làm sạch dữ liệu trong python github

Làm sạch dữ liệu bằng numpy và gấu trúc

Thành thật mà nói, phần lớn thời gian mà một nhà khoa học dữ liệu dành là không thực hiện tất cả các mô hình thực sự tuyệt vời mà tất cả chúng ta đều muốn làm, đó là việc chuẩn bị dữ liệu, thao túng, báo cáo, vẽ đồ thị đó là 80% -90% công việc bây giờ .

Jared Lander - //changelog.com/practicalai/7

Không biết xấu hổ bị đánh cắp từ Khảo sát Crowdflower 2016:

Những điều mà các nhà khoa học dữ liệu làm nhất là những điều họ thích nhất.

Từ cùng một cuộc khảo sát:

[Lưu ý rằng đồ họa trên dựa trên khảo sát năm 2016.]2016 survey.]

Tại các cuộc gặp gỡ, tôi đã nghe ít nhất một nhà khoa học dữ liệu nói rằng phần lớn thời gian của họ được dành để làm sạch dữ liệu nên khi tôi chạy qua bài báo Realpython tuyệt vời này, tôi đã quyết định dùng thử (bài báo cho thấy khoảng 80% thời gian của các nhà khoa học dữ liệu được dành Dữ liệu làm sạch).

Khuyến nghị là sử dụng máy tính xách tay Jupyter nhưng tôi đã chọn sử dụng ipython.

Tôi cũng đã tạo một phiên bản hàng loạt cho vui: Winston_Wolfe.py

Các điều khoản khác

Làm sạch dữ liệu cũng được gọi là gây tranh cãi dữ liệu, dữ liệu, công việc của người gác cổng dữ liệu và chuẩn bị dữ liệu. Tất cả những điều này đề cập đến việc chuẩn bị dữ liệu để ăn vào một luồng xử lý dữ liệu nào đó. Máy tính rất không khoan dung về sự khác biệt định dạng, vì vậy tất cả các dữ liệu phải được định dạng lại để phù hợp với định dạng tiêu chuẩn (hoặc "sạch"). Thiếu dữ liệu và bộ dữ liệu một phần có thể có vấn đề, vì vậy mục tiêu ban đầu là xác định sự thiếu hụt dữ liệu trước khi chúng dẫn đến kết quả giả. is also referred to as Data Wrangling, Data Munging, Data Janitor Work and Data Preparation. All of these refer to preparing data for ingestion into a data processing stream of some kind. Computers are very intolerant of format differences, so all of the data must be reformatted to conform to a standard (or "clean") format. Missing data and partial datasets can be problematic, so an initial goal is to identify data deficiencies before they lead to spurious results.

[Đôi khi nó không được đề cập ở tất cả, chỉ ngụ ý. Nói chung, không thể thực hiện một công việc ETL (trích xuất, biến đổi và tải) mà không thực hiện ít nhất một số làm sạch dữ liệu. Nếu bạn được yêu cầu ước tính thời gian cho một công việc ETL, hãy nhớ nhân tố theo thời gian để kiểm tra dữ liệu & làm sạch dữ liệu. Không đề cập đến cách xử lý các ngoại lệ (thả hay không? Nếu vậy, điểm cắt tốt là gì? Vv).].implied. It is generally not possible to carry out an ETL (Extract, Transform and Load) job without doing at least some data cleaning. If you are asked for a time estimate for an ETL job, remember to factor in time for data examination & data cleaning. Not to mention how to handle outliers (drop or not? if so, what is a good cutoff point? etc.).]

Các yêu cầu khác có thể bao gồm các tập dữ liệu bình thường hóa, thường có nghĩa là mở rộng dữ liệu thành các giá trị từ 0 đến 1 (điều này cho phép một số loại phân tích số nhất định).normalizing data sets, which generally means scaling the data to values between 0 and 1 (this enables certain types of numerical analysis).

Kết quả cuối cùng đôi khi có thể được gọi là dữ liệu gọn gàng, tuy nhiên điều quan trọng cần nhớ là làm sạch dữ liệu không phải lúc nào cũng là nhiệm vụ một lần. Việc sử dụng tiếp theo của bất kỳ bộ dữ liệu nhất định có thể làm nổi bật các chi tiết cần được làm sạch thêm.tidy data, however it is important to remember that data cleaning is not always a one-time task. The further use of any given dataset may well highlight details that need further cleaning.

Thăm dò

Hãy bắt đầu với bộ dữ liệu đầu tiên của chúng tôi.

Điều đầu tiên là hãy xem dữ liệu. Ở đây chúng tôi sẽ sử dụng lệnh >>> df['Identifier'].is_unique True >>>6 để kiểm tra 5 bản ghi đầu tiên của tệp đầu vào của chúng tôi (>>> df['Identifier'].is_unique True >>>7 là lệnh cũ *nix cũ hiển thị đầu của tệp được chỉ định và ký tự >>> df['Identifier'].is_unique True >>>8 từ lâu đã được sử dụng trong *Nix như một ký tự tiếp tục; Ở đây các cột dữ liệu bị phá vỡ để không tràn ra chiều rộng màn hình có sẵn):head of the specified file; and the >>> df['Identifier'].is_unique True >>>8 character has long been used in *nix as a continuation character; here the data columns are broken up so as to not overflow the available screen width):

>>> import pandas as pd >>> import numpy as np >>> df = pd.read_csv('Datasets/BL-Flickr-Images-Book.csv') >>> df.head() Identifier Edition Statement Place of Publication \ 0 206 NaN London 1 216 NaN London; Virtue & Yorston 2 218 NaN London 3 472 NaN London 4 480 A new edition, revised, etc. London Date of Publication Publisher \ 0 1879 [1878] S. Tinsley & Co. 1 1868 Virtue & Co. 2 1869 Bradbury, Evans & Co. 3 1851 James Darling 4 1857 Wertheim & Macintosh Title Author \ 0 Walter Forbes. [A novel.] By A. A A. A. 1 All for Greed. [A novel. The dedication signed... A., A. A. 2 Love the Avenger. By the author ofAll for Gr... A., A. A. 3 Welsh Sketches, chiefly ecclesiastical, to the... A., E. S. 4 [The World in which I live, and my place in it... A., E. S. Contributors Corporate Author \ 0 FORBES, Walter. NaN 1 BLAZE DE BURY, Marie Pauline Rose - Baroness NaN 2 BLAZE DE BURY, Marie Pauline Rose - Baroness NaN 3 Appleyard, Ernest Silvanus. NaN 4 BROOME, John Henry. NaN Corporate Contributors Former owner Engraver Issuance type \ 0 NaN NaN NaN monographic 1 NaN NaN NaN monographic 2 NaN NaN NaN monographic 3 NaN NaN NaN monographic 4 NaN NaN NaN monographic Flickr URL \ 0 http://www.flickr.com/photos/britishlibrary/ta... 1 http://www.flickr.com/photos/britishlibrary/ta... 2 http://www.flickr.com/photos/britishlibrary/ta... 3 http://www.flickr.com/photos/britishlibrary/ta... 4 http://www.flickr.com/photos/britishlibrary/ta... Shelfmarks 0 British Library HMNTS 12641.b.30. 1 British Library HMNTS 12626.cc.2. 2 British Library HMNTS 12625.dd.1. 3 British Library HMNTS 10369.bbb.15. 4 British Library HMNTS 9007.d.28. >>>

[Để sử dụng nhiều dữ liệu hơn >>> df['Identifier'].is_unique True >>>9.]

Xử lý

Bây giờ chúng ta hãy loại bỏ bất kỳ cột nào chúng ta không cần:

>>> to_drop = ['Edition Statement', ... 'Corporate Author', ... 'Corporate Contributors', ... 'Former owner', ... 'Engraver', ... 'Contributors', ... 'Issuance type', ... 'Shelfmarks'] >>> df.drop(to_drop, inplace=True, axis=1) >>> df.head() Identifier Place of Publication Date of Publication \ 0 206 London 1879 [1878] 1 216 London; Virtue & Yorston 1868 2 218 London 1869 3 472 London 1851 4 480 London 1857 Publisher Title \ 0 S. Tinsley & Co. Walter Forbes. [A novel.] By A. A 1 Virtue & Co. All for Greed. [A novel. The dedication signed... 2 Bradbury, Evans & Co. Love the Avenger. By the author ofAll for Gr... 3 James Darling Welsh Sketches, chiefly ecclesiastical, to the... 4 Wertheim & Macintosh [The World in which I live, and my place in it... Author Flickr URL 0 A. A. http://www.flickr.com/photos/britishlibrary/ta... 1 A., A. A. http://www.flickr.com/photos/britishlibrary/ta... 2 A., A. A. http://www.flickr.com/photos/britishlibrary/ta... 3 A., E. S. http://www.flickr.com/photos/britishlibrary/ta... 4 A., E. S. http://www.flickr.com/photos/britishlibrary/ta... >>>

Và bây giờ chúng tôi xuống đến sáu cột.

Bài viết cho thấy rằng nếu bạn biết trước những cột nào bạn muốn sử dụng, một tùy chọn khác là chuyển chúng đến đối số >>> df = df.set_index('Identifier') >>> df.head() Place of Publication Date of Publication \ Identifier 206 London 1879 [1878] 216 London; Virtue & Yorston 1868 218 London 1869 472 London 1851 480 London 1857 Publisher \ Identifier 206 S. Tinsley & Co. 216 Virtue & Co. 218 Bradbury, Evans & Co. 472 James Darling 480 Wertheim & Macintosh Title Author \ Identifier 206 Walter Forbes. [A novel.] By A. A A. A. 216 All for Greed. [A novel. The dedication signed... A., A. A. 218 Love the Avenger. By the author ofAll for Gr... A., A. A. 472 Welsh Sketches, chiefly ecclesiastical, to the... A., E. S. 480 [The World in which I live, and my place in it... A., E. S. Flickr URL Identifier 206 http://www.flickr.com/photos/britishlibrary/ta... 216 http://www.flickr.com/photos/britishlibrary/ta... 218 http://www.flickr.com/photos/britishlibrary/ta... 472 http://www.flickr.com/photos/britishlibrary/ta... 480 http://www.flickr.com/photos/britishlibrary/ta... >>>0 của >>> df = df.set_index('Identifier') >>> df.head() Place of Publication Date of Publication \ Identifier 206 London 1879 [1878] 216 London; Virtue & Yorston 1868 218 London 1869 472 London 1851 480 London 1857 Publisher \ Identifier 206 S. Tinsley & Co. 216 Virtue & Co. 218 Bradbury, Evans & Co. 472 James Darling 480 Wertheim & Macintosh Title Author \ Identifier 206 Walter Forbes. [A novel.] By A. A A. A. 216 All for Greed. [A novel. The dedication signed... A., A. A. 218 Love the Avenger. By the author ofAll for Gr... A., A. A. 472 Welsh Sketches, chiefly ecclesiastical, to the... A., E. S. 480 [The World in which I live, and my place in it... A., E. S. Flickr URL Identifier 206 http://www.flickr.com/photos/britishlibrary/ta... 216 http://www.flickr.com/photos/britishlibrary/ta... 218 http://www.flickr.com/photos/britishlibrary/ta... 472 http://www.flickr.com/photos/britishlibrary/ta... 480 http://www.flickr.com/photos/britishlibrary/ta... >>>1.

Lập chỉ mục

Mặc dù chúng tôi hiện đang xuống sáu cột, nhưng nếu chúng tôi viết tệp này, chúng tôi sẽ thấy rằng >>> df = df.set_index('Identifier') >>> df.head() Place of Publication Date of Publication \ Identifier 206 London 1879 [1878] 216 London; Virtue & Yorston 1868 218 London 1869 472 London 1851 480 London 1857 Publisher \ Identifier 206 S. Tinsley & Co. 216 Virtue & Co. 218 Bradbury, Evans & Co. 472 James Darling 480 Wertheim & Macintosh Title Author \ Identifier 206 Walter Forbes. [A novel.] By A. A A. A. 216 All for Greed. [A novel. The dedication signed... A., A. A. 218 Love the Avenger. By the author ofAll for Gr... A., A. A. 472 Welsh Sketches, chiefly ecclesiastical, to the... A., E. S. 480 [The World in which I live, and my place in it... A., E. S. Flickr URL Identifier 206 http://www.flickr.com/photos/britishlibrary/ta... 216 http://www.flickr.com/photos/britishlibrary/ta... 218 http://www.flickr.com/photos/britishlibrary/ta... 472 http://www.flickr.com/photos/britishlibrary/ta... 480 http://www.flickr.com/photos/britishlibrary/ta... >>>2 đã chuẩn bị một chỉ mục cho mỗi mục. Có vẻ như cột >>> df = df.set_index('Identifier') >>> df.head() Place of Publication Date of Publication \ Identifier 206 London 1879 [1878] 216 London; Virtue & Yorston 1868 218 London 1869 472 London 1851 480 London 1857 Publisher \ Identifier 206 S. Tinsley & Co. 216 Virtue & Co. 218 Bradbury, Evans & Co. 472 James Darling 480 Wertheim & Macintosh Title Author \ Identifier 206 Walter Forbes. [A novel.] By A. A A. A. 216 All for Greed. [A novel. The dedication signed... A., A. A. 218 Love the Avenger. By the author ofAll for Gr... A., A. A. 472 Welsh Sketches, chiefly ecclesiastical, to the... A., E. S. 480 [The World in which I live, and my place in it... A., E. S. Flickr URL Identifier 206 http://www.flickr.com/photos/britishlibrary/ta... 216 http://www.flickr.com/photos/britishlibrary/ta... 218 http://www.flickr.com/photos/britishlibrary/ta... 472 http://www.flickr.com/photos/britishlibrary/ta... 480 http://www.flickr.com/photos/britishlibrary/ta... >>>3 là duy nhất, hãy kiểm tra điều này:

>>> df['Identifier'].is_unique True >>>

Được rồi, có vẻ như chúng ta có thể sử dụng cột này làm chỉ mục:

>>> df = df.set_index('Identifier') >>> df.head() Place of Publication Date of Publication \ Identifier 206 London 1879 [1878] 216 London; Virtue & Yorston 1868 218 London 1869 472 London 1851 480 London 1857 Publisher \ Identifier 206 S. Tinsley & Co. 216 Virtue & Co. 218 Bradbury, Evans & Co. 472 James Darling 480 Wertheim & Macintosh Title Author \ Identifier 206 Walter Forbes. [A novel.] By A. A A. A. 216 All for Greed. [A novel. The dedication signed... A., A. A. 218 Love the Avenger. By the author ofAll for Gr... A., A. A. 472 Welsh Sketches, chiefly ecclesiastical, to the... A., E. S. 480 [The World in which I live, and my place in it... A., E. S. Flickr URL Identifier 206 http://www.flickr.com/photos/britishlibrary/ta... 216 http://www.flickr.com/photos/britishlibrary/ta... 218 http://www.flickr.com/photos/britishlibrary/ta... 472 http://www.flickr.com/photos/britishlibrary/ta... 480 http://www.flickr.com/photos/britishlibrary/ta... >>>

Đúng, hoạt động.

Bài báo hiện chỉ ra rằng các chỉ mục của Pandas không đảm bảo bất kỳ sự đảm bảo nào về tính duy nhất, mặc dù nhiều hoạt động lập chỉ mục và hợp nhất sẽ chạy nhanh hơn nếu chỉ mục là duy nhất.is unique.

Bây giờ chúng ta có thể sử dụng >>> df = df.set_index('Identifier') >>> df.head() Place of Publication Date of Publication \ Identifier 206 London 1879 [1878] 216 London; Virtue & Yorston 1868 218 London 1869 472 London 1851 480 London 1857 Publisher \ Identifier 206 S. Tinsley & Co. 216 Virtue & Co. 218 Bradbury, Evans & Co. 472 James Darling 480 Wertheim & Macintosh Title Author \ Identifier 206 Walter Forbes. [A novel.] By A. A A. A. 216 All for Greed. [A novel. The dedication signed... A., A. A. 218 Love the Avenger. By the author ofAll for Gr... A., A. A. 472 Welsh Sketches, chiefly ecclesiastical, to the... A., E. S. 480 [The World in which I live, and my place in it... A., E. S. Flickr URL Identifier 206 http://www.flickr.com/photos/britishlibrary/ta... 216 http://www.flickr.com/photos/britishlibrary/ta... 218 http://www.flickr.com/photos/britishlibrary/ta... 472 http://www.flickr.com/photos/britishlibrary/ta... 480 http://www.flickr.com/photos/britishlibrary/ta... >>>4 để thực hiện định vị dựa trên khóa:

>>> df.loc[216] Place of Publication London; Virtue & Yorston Date of Publication 1868 Publisher Virtue & Co. Title All for Greed. [A novel. The dedication signed... Author A., A. A. Flickr URL http://www.flickr.com/photos/britishlibrary/ta... Name: 216, dtype: object >>>

Hoặc chúng tôi có thể sử dụng >>> df = df.set_index('Identifier') >>> df.head() Place of Publication Date of Publication \ Identifier 206 London 1879 [1878] 216 London; Virtue & Yorston 1868 218 London 1869 472 London 1851 480 London 1857 Publisher \ Identifier 206 S. Tinsley & Co. 216 Virtue & Co. 218 Bradbury, Evans & Co. 472 James Darling 480 Wertheim & Macintosh Title Author \ Identifier 206 Walter Forbes. [A novel.] By A. A A. A. 216 All for Greed. [A novel. The dedication signed... A., A. A. 218 Love the Avenger. By the author ofAll for Gr... A., A. A. 472 Welsh Sketches, chiefly ecclesiastical, to the... A., E. S. 480 [The World in which I live, and my place in it... A., E. S. Flickr URL Identifier 206 http://www.flickr.com/photos/britishlibrary/ta... 216 http://www.flickr.com/photos/britishlibrary/ta... 218 http://www.flickr.com/photos/britishlibrary/ta... 472 http://www.flickr.com/photos/britishlibrary/ta... 480 http://www.flickr.com/photos/britishlibrary/ta... >>>5 để truy cập các mục nhập của chúng tôi bằng chỉ mục (thay vì khóa):

>>> df.iloc[1] Place of Publication London; Virtue & Yorston Date of Publication 1868 Publisher Virtue & Co. Title All for Greed. [A novel. The dedication signed... Author A., A. A. Flickr URL http://www.flickr.com/photos/britishlibrary/ta... Name: 216, dtype: object >>>

Chúng tôi cũng có thể đặt chỉ mục tại chỗ của mình:in-place:

df.set_index('Identifier', inplace=True)

Thay vì:

>>> df = df.set_index('Identifier')

Làm sạch các trường dữ liệu

Hãy xem những kiểu dữ liệu chúng ta có:

>>> df.get_dtype_counts() object 6 dtype: int64 >>>

Được rồi, vì vậy hãy kiểm tra các vấn đề định dạng:

>>> import pandas as pd >>> import numpy as np >>> df = pd.read_csv('Datasets/BL-Flickr-Images-Book.csv') >>> df.head() Identifier Edition Statement Place of Publication \ 0 206 NaN London 1 216 NaN London; Virtue & Yorston 2 218 NaN London 3 472 NaN London 4 480 A new edition, revised, etc. London Date of Publication Publisher \ 0 1879 [1878] S. Tinsley & Co. 1 1868 Virtue & Co. 2 1869 Bradbury, Evans & Co. 3 1851 James Darling 4 1857 Wertheim & Macintosh Title Author \ 0 Walter Forbes. [A novel.] By A. A A. A. 1 All for Greed. [A novel. The dedication signed... A., A. A. 2 Love the Avenger. By the author ofAll for Gr... A., A. A. 3 Welsh Sketches, chiefly ecclesiastical, to the... A., E. S. 4 [The World in which I live, and my place in it... A., E. S. Contributors Corporate Author \ 0 FORBES, Walter. NaN 1 BLAZE DE BURY, Marie Pauline Rose - Baroness NaN 2 BLAZE DE BURY, Marie Pauline Rose - Baroness NaN 3 Appleyard, Ernest Silvanus. NaN 4 BROOME, John Henry. NaN Corporate Contributors Former owner Engraver Issuance type \ 0 NaN NaN NaN monographic 1 NaN NaN NaN monographic 2 NaN NaN NaN monographic 3 NaN NaN NaN monographic 4 NaN NaN NaN monographic Flickr URL \ 0 http://www.flickr.com/photos/britishlibrary/ta... 1 http://www.flickr.com/photos/britishlibrary/ta... 2 http://www.flickr.com/photos/britishlibrary/ta... 3 http://www.flickr.com/photos/britishlibrary/ta... 4 http://www.flickr.com/photos/britishlibrary/ta... Shelfmarks 0 British Library HMNTS 12641.b.30. 1 British Library HMNTS 12626.cc.2. 2 British Library HMNTS 12625.dd.1. 3 British Library HMNTS 10369.bbb.15. 4 British Library HMNTS 9007.d.28. >>>0

Và chúng ta sẽ cần phải dọn dẹp 'ngày xuất bản'. Vì vậy, chúng tôi sẽ sử dụng một biểu thức thông thường để trích xuất các giá trị được làm sạch của chúng tôi:

>>> import pandas as pd >>> import numpy as np >>> df = pd.read_csv('Datasets/BL-Flickr-Images-Book.csv') >>> df.head() Identifier Edition Statement Place of Publication \ 0 206 NaN London 1 216 NaN London; Virtue & Yorston 2 218 NaN London 3 472 NaN London 4 480 A new edition, revised, etc. London Date of Publication Publisher \ 0 1879 [1878] S. Tinsley & Co. 1 1868 Virtue & Co. 2 1869 Bradbury, Evans & Co. 3 1851 James Darling 4 1857 Wertheim & Macintosh Title Author \ 0 Walter Forbes. [A novel.] By A. A A. A. 1 All for Greed. [A novel. The dedication signed... A., A. A. 2 Love the Avenger. By the author ofAll for Gr... A., A. A. 3 Welsh Sketches, chiefly ecclesiastical, to the... A., E. S. 4 [The World in which I live, and my place in it... A., E. S. Contributors Corporate Author \ 0 FORBES, Walter. NaN 1 BLAZE DE BURY, Marie Pauline Rose - Baroness NaN 2 BLAZE DE BURY, Marie Pauline Rose - Baroness NaN 3 Appleyard, Ernest Silvanus. NaN 4 BROOME, John Henry. NaN Corporate Contributors Former owner Engraver Issuance type \ 0 NaN NaN NaN monographic 1 NaN NaN NaN monographic 2 NaN NaN NaN monographic 3 NaN NaN NaN monographic 4 NaN NaN NaN monographic Flickr URL \ 0 http://www.flickr.com/photos/britishlibrary/ta... 1 http://www.flickr.com/photos/britishlibrary/ta... 2 http://www.flickr.com/photos/britishlibrary/ta... 3 http://www.flickr.com/photos/britishlibrary/ta... 4 http://www.flickr.com/photos/britishlibrary/ta... Shelfmarks 0 British Library HMNTS 12641.b.30. 1 British Library HMNTS 12626.cc.2. 2 British Library HMNTS 12625.dd.1. 3 British Library HMNTS 10369.bbb.15. 4 British Library HMNTS 9007.d.28. >>>1

Bây giờ hãy chuyển đổi chúng thành loại số và sao chép lại:

>>> import pandas as pd >>> import numpy as np >>> df = pd.read_csv('Datasets/BL-Flickr-Images-Book.csv') >>> df.head() Identifier Edition Statement Place of Publication \ 0 206 NaN London 1 216 NaN London; Virtue & Yorston 2 218 NaN London 3 472 NaN London 4 480 A new edition, revised, etc. London Date of Publication Publisher \ 0 1879 [1878] S. Tinsley & Co. 1 1868 Virtue & Co. 2 1869 Bradbury, Evans & Co. 3 1851 James Darling 4 1857 Wertheim & Macintosh Title Author \ 0 Walter Forbes. [A novel.] By A. A A. A. 1 All for Greed. [A novel. The dedication signed... A., A. A. 2 Love the Avenger. By the author ofAll for Gr... A., A. A. 3 Welsh Sketches, chiefly ecclesiastical, to the... A., E. S. 4 [The World in which I live, and my place in it... A., E. S. Contributors Corporate Author \ 0 FORBES, Walter. NaN 1 BLAZE DE BURY, Marie Pauline Rose - Baroness NaN 2 BLAZE DE BURY, Marie Pauline Rose - Baroness NaN 3 Appleyard, Ernest Silvanus. NaN 4 BROOME, John Henry. NaN Corporate Contributors Former owner Engraver Issuance type \ 0 NaN NaN NaN monographic 1 NaN NaN NaN monographic 2 NaN NaN NaN monographic 3 NaN NaN NaN monographic 4 NaN NaN NaN monographic Flickr URL \ 0 http://www.flickr.com/photos/britishlibrary/ta... 1 http://www.flickr.com/photos/britishlibrary/ta... 2 http://www.flickr.com/photos/britishlibrary/ta... 3 http://www.flickr.com/photos/britishlibrary/ta... 4 http://www.flickr.com/photos/britishlibrary/ta... Shelfmarks 0 British Library HMNTS 12641.b.30. 1 British Library HMNTS 12626.cc.2. 2 British Library HMNTS 12625.dd.1. 3 British Library HMNTS 10369.bbb.15. 4 British Library HMNTS 9007.d.28. >>>2

Lưu ý rằng phao có một phần thập phân, có thể trông hơi kỳ lạ:

>>> import pandas as pd >>> import numpy as np >>> df = pd.read_csv('Datasets/BL-Flickr-Images-Book.csv') >>> df.head() Identifier Edition Statement Place of Publication \ 0 206 NaN London 1 216 NaN London; Virtue & Yorston 2 218 NaN London 3 472 NaN London 4 480 A new edition, revised, etc. London Date of Publication Publisher \ 0 1879 [1878] S. Tinsley & Co. 1 1868 Virtue & Co. 2 1869 Bradbury, Evans & Co. 3 1851 James Darling 4 1857 Wertheim & Macintosh Title Author \ 0 Walter Forbes. [A novel.] By A. A A. A. 1 All for Greed. [A novel. The dedication signed... A., A. A. 2 Love the Avenger. By the author ofAll for Gr... A., A. A. 3 Welsh Sketches, chiefly ecclesiastical, to the... A., E. S. 4 [The World in which I live, and my place in it... A., E. S. Contributors Corporate Author \ 0 FORBES, Walter. NaN 1 BLAZE DE BURY, Marie Pauline Rose - Baroness NaN 2 BLAZE DE BURY, Marie Pauline Rose - Baroness NaN 3 Appleyard, Ernest Silvanus. NaN 4 BROOME, John Henry. NaN Corporate Contributors Former owner Engraver Issuance type \ 0 NaN NaN NaN monographic 1 NaN NaN NaN monographic 2 NaN NaN NaN monographic 3 NaN NaN NaN monographic 4 NaN NaN NaN monographic Flickr URL \ 0 http://www.flickr.com/photos/britishlibrary/ta... 1 http://www.flickr.com/photos/britishlibrary/ta... 2 http://www.flickr.com/photos/britishlibrary/ta... 3 http://www.flickr.com/photos/britishlibrary/ta... 4 http://www.flickr.com/photos/britishlibrary/ta... Shelfmarks 0 British Library HMNTS 12641.b.30. 1 British Library HMNTS 12626.cc.2. 2 British Library HMNTS 12625.dd.1. 3 British Library HMNTS 10369.bbb.15. 4 British Library HMNTS 9007.d.28. >>>3

Cho đến nay chúng tôi vừa sử dụng >>> df = df.set_index('Identifier') >>> df.head() Place of Publication Date of Publication \ Identifier 206 London 1879 [1878] 216 London; Virtue & Yorston 1868 218 London 1869 472 London 1851 480 London 1857 Publisher \ Identifier 206 S. Tinsley & Co. 216 Virtue & Co. 218 Bradbury, Evans & Co. 472 James Darling 480 Wertheim & Macintosh Title Author \ Identifier 206 Walter Forbes. [A novel.] By A. A A. A. 216 All for Greed. [A novel. The dedication signed... A., A. A. 218 Love the Avenger. By the author ofAll for Gr... A., A. A. 472 Welsh Sketches, chiefly ecclesiastical, to the... A., E. S. 480 [The World in which I live, and my place in it... A., E. S. Flickr URL Identifier 206 http://www.flickr.com/photos/britishlibrary/ta... 216 http://www.flickr.com/photos/britishlibrary/ta... 218 http://www.flickr.com/photos/britishlibrary/ta... 472 http://www.flickr.com/photos/britishlibrary/ta... 480 http://www.flickr.com/photos/britishlibrary/ta... >>>2, cho phép sử dụng >>> df = df.set_index('Identifier') >>> df.head() Place of Publication Date of Publication \ Identifier 206 London 1879 [1878] 216 London; Virtue & Yorston 1868 218 London 1869 472 London 1851 480 London 1857 Publisher \ Identifier 206 S. Tinsley & Co. 216 Virtue & Co. 218 Bradbury, Evans & Co. 472 James Darling 480 Wertheim & Macintosh Title Author \ Identifier 206 Walter Forbes. [A novel.] By A. A A. A. 216 All for Greed. [A novel. The dedication signed... A., A. A. 218 Love the Avenger. By the author ofAll for Gr... A., A. A. 472 Welsh Sketches, chiefly ecclesiastical, to the... A., E. S. 480 [The World in which I live, and my place in it... A., E. S. Flickr URL Identifier 206 http://www.flickr.com/photos/britishlibrary/ta... 216 http://www.flickr.com/photos/britishlibrary/ta... 218 http://www.flickr.com/photos/britishlibrary/ta... 472 http://www.flickr.com/photos/britishlibrary/ta... 480 http://www.flickr.com/photos/britishlibrary/ta... >>>7.

Làm sạch nhiều trường dữ liệu (lần này là với >>> df = df.set_index('Identifier') >>> df.head() Place of Publication Date of Publication \ Identifier 206 London 1879 [1878] 216 London; Virtue & Yorston 1868 218 London 1869 472 London 1851 480 London 1857 Publisher \ Identifier 206 S. Tinsley & Co. 216 Virtue & Co. 218 Bradbury, Evans & Co. 472 James Darling 480 Wertheim & Macintosh Title Author \ Identifier 206 Walter Forbes. [A novel.] By A. A A. A. 216 All for Greed. [A novel. The dedication signed... A., A. A. 218 Love the Avenger. By the author ofAll for Gr... A., A. A. 472 Welsh Sketches, chiefly ecclesiastical, to the... A., E. S. 480 [The World in which I live, and my place in it... A., E. S. Flickr URL Identifier 206 http://www.flickr.com/photos/britishlibrary/ta... 216 http://www.flickr.com/photos/britishlibrary/ta... 218 http://www.flickr.com/photos/britishlibrary/ta... 472 http://www.flickr.com/photos/britishlibrary/ta... 480 http://www.flickr.com/photos/britishlibrary/ta... >>>7)

Hãy xem xét 'Địa điểm xuất bản' của chúng tôi:

>>> import pandas as pd >>> import numpy as np >>> df = pd.read_csv('Datasets/BL-Flickr-Images-Book.csv') >>> df.head() Identifier Edition Statement Place of Publication \ 0 206 NaN London 1 216 NaN London; Virtue & Yorston 2 218 NaN London 3 472 NaN London 4 480 A new edition, revised, etc. London Date of Publication Publisher \ 0 1879 [1878] S. Tinsley & Co. 1 1868 Virtue & Co. 2 1869 Bradbury, Evans & Co. 3 1851 James Darling 4 1857 Wertheim & Macintosh Title Author \ 0 Walter Forbes. [A novel.] By A. A A. A. 1 All for Greed. [A novel. The dedication signed... A., A. A. 2 Love the Avenger. By the author ofAll for Gr... A., A. A. 3 Welsh Sketches, chiefly ecclesiastical, to the... A., E. S. 4 [The World in which I live, and my place in it... A., E. S. Contributors Corporate Author \ 0 FORBES, Walter. NaN 1 BLAZE DE BURY, Marie Pauline Rose - Baroness NaN 2 BLAZE DE BURY, Marie Pauline Rose - Baroness NaN 3 Appleyard, Ernest Silvanus. NaN 4 BROOME, John Henry. NaN Corporate Contributors Former owner Engraver Issuance type \ 0 NaN NaN NaN monographic 1 NaN NaN NaN monographic 2 NaN NaN NaN monographic 3 NaN NaN NaN monographic 4 NaN NaN NaN monographic Flickr URL \ 0 http://www.flickr.com/photos/britishlibrary/ta... 1 http://www.flickr.com/photos/britishlibrary/ta... 2 http://www.flickr.com/photos/britishlibrary/ta... 3 http://www.flickr.com/photos/britishlibrary/ta... 4 http://www.flickr.com/photos/britishlibrary/ta... Shelfmarks 0 British Library HMNTS 12641.b.30. 1 British Library HMNTS 12626.cc.2. 2 British Library HMNTS 12625.dd.1. 3 British Library HMNTS 10369.bbb.15. 4 British Library HMNTS 9007.d.28. >>>4

Hãy xem nếu chúng ta có thể cô lập London:

>>> import pandas as pd >>> import numpy as np >>> df = pd.read_csv('Datasets/BL-Flickr-Images-Book.csv') >>> df.head() Identifier Edition Statement Place of Publication \ 0 206 NaN London 1 216 NaN London; Virtue & Yorston 2 218 NaN London 3 472 NaN London 4 480 A new edition, revised, etc. London Date of Publication Publisher \ 0 1879 [1878] S. Tinsley & Co. 1 1868 Virtue & Co. 2 1869 Bradbury, Evans & Co. 3 1851 James Darling 4 1857 Wertheim & Macintosh Title Author \ 0 Walter Forbes. [A novel.] By A. A A. A. 1 All for Greed. [A novel. The dedication signed... A., A. A. 2 Love the Avenger. By the author ofAll for Gr... A., A. A. 3 Welsh Sketches, chiefly ecclesiastical, to the... A., E. S. 4 [The World in which I live, and my place in it... A., E. S. Contributors Corporate Author \ 0 FORBES, Walter. NaN 1 BLAZE DE BURY, Marie Pauline Rose - Baroness NaN 2 BLAZE DE BURY, Marie Pauline Rose - Baroness NaN 3 Appleyard, Ernest Silvanus. NaN 4 BROOME, John Henry. NaN Corporate Contributors Former owner Engraver Issuance type \ 0 NaN NaN NaN monographic 1 NaN NaN NaN monographic 2 NaN NaN NaN monographic 3 NaN NaN NaN monographic 4 NaN NaN NaN monographic Flickr URL \ 0 http://www.flickr.com/photos/britishlibrary/ta... 1 http://www.flickr.com/photos/britishlibrary/ta... 2 http://www.flickr.com/photos/britishlibrary/ta... 3 http://www.flickr.com/photos/britishlibrary/ta... 4 http://www.flickr.com/photos/britishlibrary/ta... Shelfmarks 0 British Library HMNTS 12641.b.30. 1 British Library HMNTS 12626.cc.2. 2 British Library HMNTS 12625.dd.1. 3 British Library HMNTS 10369.bbb.15. 4 British Library HMNTS 9007.d.28. >>>5

Hãy thêm Oxford và làm sạch cả hai:

>>> import pandas as pd >>> import numpy as np >>> df = pd.read_csv('Datasets/BL-Flickr-Images-Book.csv') >>> df.head() Identifier Edition Statement Place of Publication \ 0 206 NaN London 1 216 NaN London; Virtue & Yorston 2 218 NaN London 3 472 NaN London 4 480 A new edition, revised, etc. London Date of Publication Publisher \ 0 1879 [1878] S. Tinsley & Co. 1 1868 Virtue & Co. 2 1869 Bradbury, Evans & Co. 3 1851 James Darling 4 1857 Wertheim & Macintosh Title Author \ 0 Walter Forbes. [A novel.] By A. A A. A. 1 All for Greed. [A novel. The dedication signed... A., A. A. 2 Love the Avenger. By the author ofAll for Gr... A., A. A. 3 Welsh Sketches, chiefly ecclesiastical, to the... A., E. S. 4 [The World in which I live, and my place in it... A., E. S. Contributors Corporate Author \ 0 FORBES, Walter. NaN 1 BLAZE DE BURY, Marie Pauline Rose - Baroness NaN 2 BLAZE DE BURY, Marie Pauline Rose - Baroness NaN 3 Appleyard, Ernest Silvanus. NaN 4 BROOME, John Henry. NaN Corporate Contributors Former owner Engraver Issuance type \ 0 NaN NaN NaN monographic 1 NaN NaN NaN monographic 2 NaN NaN NaN monographic 3 NaN NaN NaN monographic 4 NaN NaN NaN monographic Flickr URL \ 0 http://www.flickr.com/photos/britishlibrary/ta... 1 http://www.flickr.com/photos/britishlibrary/ta... 2 http://www.flickr.com/photos/britishlibrary/ta... 3 http://www.flickr.com/photos/britishlibrary/ta... 4 http://www.flickr.com/photos/britishlibrary/ta... Shelfmarks 0 British Library HMNTS 12641.b.30. 1 British Library HMNTS 12626.cc.2. 2 British Library HMNTS 12625.dd.1. 3 British Library HMNTS 10369.bbb.15. 4 British Library HMNTS 9007.d.28. >>>6

Chúng tôi có thể làm sạch khoảng trắng dẫn đầu và kéo dài bằng một cái gì đó như sau:

>>> import pandas as pd >>> import numpy as np >>> df = pd.read_csv('Datasets/BL-Flickr-Images-Book.csv') >>> df.head() Identifier Edition Statement Place of Publication \ 0 206 NaN London 1 216 NaN London; Virtue & Yorston 2 218 NaN London 3 472 NaN London 4 480 A new edition, revised, etc. London Date of Publication Publisher \ 0 1879 [1878] S. Tinsley & Co. 1 1868 Virtue & Co. 2 1869 Bradbury, Evans & Co. 3 1851 James Darling 4 1857 Wertheim & Macintosh Title Author \ 0 Walter Forbes. [A novel.] By A. A A. A. 1 All for Greed. [A novel. The dedication signed... A., A. A. 2 Love the Avenger. By the author ofAll for Gr... A., A. A. 3 Welsh Sketches, chiefly ecclesiastical, to the... A., E. S. 4 [The World in which I live, and my place in it... A., E. S. Contributors Corporate Author \ 0 FORBES, Walter. NaN 1 BLAZE DE BURY, Marie Pauline Rose - Baroness NaN 2 BLAZE DE BURY, Marie Pauline Rose - Baroness NaN 3 Appleyard, Ernest Silvanus. NaN 4 BROOME, John Henry. NaN Corporate Contributors Former owner Engraver Issuance type \ 0 NaN NaN NaN monographic 1 NaN NaN NaN monographic 2 NaN NaN NaN monographic 3 NaN NaN NaN monographic 4 NaN NaN NaN monographic Flickr URL \ 0 http://www.flickr.com/photos/britishlibrary/ta... 1 http://www.flickr.com/photos/britishlibrary/ta... 2 http://www.flickr.com/photos/britishlibrary/ta... 3 http://www.flickr.com/photos/britishlibrary/ta... 4 http://www.flickr.com/photos/britishlibrary/ta... Shelfmarks 0 British Library HMNTS 12641.b.30. 1 British Library HMNTS 12626.cc.2. 2 British Library HMNTS 12625.dd.1. 3 British Library HMNTS 10369.bbb.15. 4 British Library HMNTS 9007.d.28. >>>7

Nhưng đơn giản hơn vẫn để tước những thứ này trên Ingress:

>>> import pandas as pd >>> import numpy as np >>> df = pd.read_csv('Datasets/BL-Flickr-Images-Book.csv') >>> df.head() Identifier Edition Statement Place of Publication \ 0 206 NaN London 1 216 NaN London; Virtue & Yorston 2 218 NaN London 3 472 NaN London 4 480 A new edition, revised, etc. London Date of Publication Publisher \ 0 1879 [1878] S. Tinsley & Co. 1 1868 Virtue & Co. 2 1869 Bradbury, Evans & Co. 3 1851 James Darling 4 1857 Wertheim & Macintosh Title Author \ 0 Walter Forbes. [A novel.] By A. A A. A. 1 All for Greed. [A novel. The dedication signed... A., A. A. 2 Love the Avenger. By the author ofAll for Gr... A., A. A. 3 Welsh Sketches, chiefly ecclesiastical, to the... A., E. S. 4 [The World in which I live, and my place in it... A., E. S. Contributors Corporate Author \ 0 FORBES, Walter. NaN 1 BLAZE DE BURY, Marie Pauline Rose - Baroness NaN 2 BLAZE DE BURY, Marie Pauline Rose - Baroness NaN 3 Appleyard, Ernest Silvanus. NaN 4 BROOME, John Henry. NaN Corporate Contributors Former owner Engraver Issuance type \ 0 NaN NaN NaN monographic 1 NaN NaN NaN monographic 2 NaN NaN NaN monographic 3 NaN NaN NaN monographic 4 NaN NaN NaN monographic Flickr URL \ 0 http://www.flickr.com/photos/britishlibrary/ta... 1 http://www.flickr.com/photos/britishlibrary/ta... 2 http://www.flickr.com/photos/britishlibrary/ta... 3 http://www.flickr.com/photos/britishlibrary/ta... 4 http://www.flickr.com/photos/britishlibrary/ta... Shelfmarks 0 British Library HMNTS 12641.b.30. 1 British Library HMNTS 12626.cc.2. 2 British Library HMNTS 12625.dd.1. 3 British Library HMNTS 10369.bbb.15. 4 British Library HMNTS 9007.d.28. >>>8

Dữ liệu phá hủy

Trên bộ dữ liệu thứ hai.

Bộ dữ liệu >>> df = df.set_index('Identifier') >>> df.head() Place of Publication Date of Publication \ Identifier 206 London 1879 [1878] 216 London; Virtue & Yorston 1868 218 London 1869 472 London 1851 480 London 1857 Publisher \ Identifier 206 S. Tinsley & Co. 216 Virtue & Co. 218 Bradbury, Evans & Co. 472 James Darling 480 Wertheim & Macintosh Title Author \ Identifier 206 Walter Forbes. [A novel.] By A. A A. A. 216 All for Greed. [A novel. The dedication signed... A., A. A. 218 Love the Avenger. By the author ofAll for Gr... A., A. A. 472 Welsh Sketches, chiefly ecclesiastical, to the... A., E. S. 480 [The World in which I live, and my place in it... A., E. S. Flickr URL Identifier 206 http://www.flickr.com/photos/britishlibrary/ta... 216 http://www.flickr.com/photos/britishlibrary/ta... 218 http://www.flickr.com/photos/britishlibrary/ta... 472 http://www.flickr.com/photos/britishlibrary/ta... 480 http://www.flickr.com/photos/britishlibrary/ta... >>>9 có cấu trúc rất nhiều.

>>> import pandas as pd >>> import numpy as np >>> df = pd.read_csv('Datasets/BL-Flickr-Images-Book.csv') >>> df.head() Identifier Edition Statement Place of Publication \ 0 206 NaN London 1 216 NaN London; Virtue & Yorston 2 218 NaN London 3 472 NaN London 4 480 A new edition, revised, etc. London Date of Publication Publisher \ 0 1879 [1878] S. Tinsley & Co. 1 1868 Virtue & Co. 2 1869 Bradbury, Evans & Co. 3 1851 James Darling 4 1857 Wertheim & Macintosh Title Author \ 0 Walter Forbes. [A novel.] By A. A A. A. 1 All for Greed. [A novel. The dedication signed... A., A. A. 2 Love the Avenger. By the author ofAll for Gr... A., A. A. 3 Welsh Sketches, chiefly ecclesiastical, to the... A., E. S. 4 [The World in which I live, and my place in it... A., E. S. Contributors Corporate Author \ 0 FORBES, Walter. NaN 1 BLAZE DE BURY, Marie Pauline Rose - Baroness NaN 2 BLAZE DE BURY, Marie Pauline Rose - Baroness NaN 3 Appleyard, Ernest Silvanus. NaN 4 BROOME, John Henry. NaN Corporate Contributors Former owner Engraver Issuance type \ 0 NaN NaN NaN monographic 1 NaN NaN NaN monographic 2 NaN NaN NaN monographic 3 NaN NaN NaN monographic 4 NaN NaN NaN monographic Flickr URL \ 0 http://www.flickr.com/photos/britishlibrary/ta... 1 http://www.flickr.com/photos/britishlibrary/ta... 2 http://www.flickr.com/photos/britishlibrary/ta... 3 http://www.flickr.com/photos/britishlibrary/ta... 4 http://www.flickr.com/photos/britishlibrary/ta... Shelfmarks 0 British Library HMNTS 12641.b.30. 1 British Library HMNTS 12626.cc.2. 2 British Library HMNTS 12625.dd.1. 3 British Library HMNTS 10369.bbb.15. 4 British Library HMNTS 9007.d.28. >>>9

Chúng ta có thể phá hủy nó như sau:

>>> to_drop = ['Edition Statement', ... 'Corporate Author', ... 'Corporate Contributors', ... 'Former owner', ... 'Engraver', ... 'Contributors', ... 'Issuance type', ... 'Shelfmarks'] >>> df.drop(to_drop, inplace=True, axis=1) >>> df.head() Identifier Place of Publication Date of Publication \ 0 206 London 1879 [1878] 1 216 London; Virtue & Yorston 1868 2 218 London 1869 3 472 London 1851 4 480 London 1857 Publisher Title \ 0 S. Tinsley & Co. Walter Forbes. [A novel.] By A. A 1 Virtue & Co. All for Greed. [A novel. The dedication signed... 2 Bradbury, Evans & Co. Love the Avenger. By the author ofAll for Gr... 3 James Darling Welsh Sketches, chiefly ecclesiastical, to the... 4 Wertheim & Macintosh [The World in which I live, and my place in it... Author Flickr URL 0 A. A. http://www.flickr.com/photos/britishlibrary/ta... 1 A., A. A. http://www.flickr.com/photos/britishlibrary/ta... 2 A., A. A. http://www.flickr.com/photos/britishlibrary/ta... 3 A., E. S. http://www.flickr.com/photos/britishlibrary/ta... 4 A., E. S. http://www.flickr.com/photos/britishlibrary/ta... >>>0

Và bây giờ chúng ta có thể tạo một DataFrame:

>>> to_drop = ['Edition Statement', ... 'Corporate Author', ... 'Corporate Contributors', ... 'Former owner', ... 'Engraver', ... 'Contributors', ... 'Issuance type', ... 'Shelfmarks'] >>> df.drop(to_drop, inplace=True, axis=1) >>> df.head() Identifier Place of Publication Date of Publication \ 0 206 London 1879 [1878] 1 216 London; Virtue & Yorston 1868 2 218 London 1869 3 472 London 1851 4 480 London 1857 Publisher Title \ 0 S. Tinsley & Co. Walter Forbes. [A novel.] By A. A 1 Virtue & Co. All for Greed. [A novel. The dedication signed... 2 Bradbury, Evans & Co. Love the Avenger. By the author ofAll for Gr... 3 James Darling Welsh Sketches, chiefly ecclesiastical, to the... 4 Wertheim & Macintosh [The World in which I live, and my place in it... Author Flickr URL 0 A. A. http://www.flickr.com/photos/britishlibrary/ta... 1 A., A. A. http://www.flickr.com/photos/britishlibrary/ta... 2 A., A. A. http://www.flickr.com/photos/britishlibrary/ta... 3 A., E. S. http://www.flickr.com/photos/britishlibrary/ta... 4 A., E. S. http://www.flickr.com/photos/britishlibrary/ta... >>>1

Hãy tạo một chức năng để làm sạch các ô dữ liệu của chúng tôi:

>>> to_drop = ['Edition Statement', ... 'Corporate Author', ... 'Corporate Contributors', ... 'Former owner', ... 'Engraver', ... 'Contributors', ... 'Issuance type', ... 'Shelfmarks'] >>> df.drop(to_drop, inplace=True, axis=1) >>> df.head() Identifier Place of Publication Date of Publication \ 0 206 London 1879 [1878] 1 216 London; Virtue & Yorston 1868 2 218 London 1869 3 472 London 1851 4 480 London 1857 Publisher Title \ 0 S. Tinsley & Co. Walter Forbes. [A novel.] By A. A 1 Virtue & Co. All for Greed. [A novel. The dedication signed... 2 Bradbury, Evans & Co. Love the Avenger. By the author ofAll for Gr... 3 James Darling Welsh Sketches, chiefly ecclesiastical, to the... 4 Wertheim & Macintosh [The World in which I live, and my place in it... Author Flickr URL 0 A. A. http://www.flickr.com/photos/britishlibrary/ta... 1 A., A. A. http://www.flickr.com/photos/britishlibrary/ta... 2 A., A. A. http://www.flickr.com/photos/britishlibrary/ta... 3 A., E. S. http://www.flickr.com/photos/britishlibrary/ta... 4 A., E. S. http://www.flickr.com/photos/britishlibrary/ta... >>>2

.

Bài báo chỉ ra rằng phương pháp >>> df.loc[216] Place of Publication London; Virtue & Yorston Date of Publication 1868 Publisher Virtue & Co. Title All for Greed. [A novel. The dedication signed... Author A., A. A. Flickr URL http://www.flickr.com/photos/britishlibrary/ta... Name: 216, dtype: object >>>2 sẽ có tác động hiệu suất đáng kể và nếu hiệu suất là một sự cân nhắc, loại điều này nên được gửi tới >>> df = df.set_index('Identifier') >>> df.head() Place of Publication Date of Publication \ Identifier 206 London 1879 [1878] 216 London; Virtue & Yorston 1868 218 London 1869 472 London 1851 480 London 1857 Publisher \ Identifier 206 S. Tinsley & Co. 216 Virtue & Co. 218 Bradbury, Evans & Co. 472 James Darling 480 Wertheim & Macintosh Title Author \ Identifier 206 Walter Forbes. [A novel.] By A. A A. A. 216 All for Greed. [A novel. The dedication signed... A., A. A. 218 Love the Avenger. By the author ofAll for Gr... A., A. A. 472 Welsh Sketches, chiefly ecclesiastical, to the... A., E. S. 480 [The World in which I live, and my place in it... A., E. S. Flickr URL Identifier 206 http://www.flickr.com/photos/britishlibrary/ta... 216 http://www.flickr.com/photos/britishlibrary/ta... 218 http://www.flickr.com/photos/britishlibrary/ta... 472 http://www.flickr.com/photos/britishlibrary/ta... 480 http://www.flickr.com/photos/britishlibrary/ta... >>>7 thay thế (nói chung, các hoạt động tương đương trong Numpy sẽ vượt trội hơn đáng kể Python bản địa).is a consideration, this type of thing should be submitted to >>> df = df.set_index('Identifier') >>> df.head() Place of Publication Date of Publication \ Identifier 206 London 1879 [1878] 216 London; Virtue & Yorston 1868 218 London 1869 472 London 1851 480 London 1857 Publisher \ Identifier 206 S. Tinsley & Co. 216 Virtue & Co. 218 Bradbury, Evans & Co. 472 James Darling 480 Wertheim & Macintosh Title Author \ Identifier 206 Walter Forbes. [A novel.] By A. A A. A. 216 All for Greed. [A novel. The dedication signed... A., A. A. 218 Love the Avenger. By the author ofAll for Gr... A., A. A. 472 Welsh Sketches, chiefly ecclesiastical, to the... A., E. S. 480 [The World in which I live, and my place in it... A., E. S. Flickr URL Identifier 206 http://www.flickr.com/photos/britishlibrary/ta... 216 http://www.flickr.com/photos/britishlibrary/ta... 218 http://www.flickr.com/photos/britishlibrary/ta... 472 http://www.flickr.com/photos/britishlibrary/ta... 480 http://www.flickr.com/photos/britishlibrary/ta... >>>7 instead (in general, equivalent operations in numpy will significantly out-perform native Python).

Thả hàng và đổi tên cột

Và bây giờ bộ dữ liệu thứ ba của chúng tôi. Hãy xem những gì chúng tôi có:

>>> to_drop = ['Edition Statement', ... 'Corporate Author', ... 'Corporate Contributors', ... 'Former owner', ... 'Engraver', ... 'Contributors', ... 'Issuance type', ... 'Shelfmarks'] >>> df.drop(to_drop, inplace=True, axis=1) >>> df.head() Identifier Place of Publication Date of Publication \ 0 206 London 1879 [1878] 1 216 London; Virtue & Yorston 1868 2 218 London 1869 3 472 London 1851 4 480 London 1857 Publisher Title \ 0 S. Tinsley & Co. Walter Forbes. [A novel.] By A. A 1 Virtue & Co. All for Greed. [A novel. The dedication signed... 2 Bradbury, Evans & Co. Love the Avenger. By the author ofAll for Gr... 3 James Darling Welsh Sketches, chiefly ecclesiastical, to the... 4 Wertheim & Macintosh [The World in which I live, and my place in it... Author Flickr URL 0 A. A. http://www.flickr.com/photos/britishlibrary/ta... 1 A., A. A. http://www.flickr.com/photos/britishlibrary/ta... 2 A., A. A. http://www.flickr.com/photos/britishlibrary/ta... 3 A., E. S. http://www.flickr.com/photos/britishlibrary/ta... 4 A., E. S. http://www.flickr.com/photos/britishlibrary/ta... >>>3

Hãy đọc nó trong:

>>> to_drop = ['Edition Statement', ... 'Corporate Author', ... 'Corporate Contributors', ... 'Former owner', ... 'Engraver', ... 'Contributors', ... 'Issuance type', ... 'Shelfmarks'] >>> df.drop(to_drop, inplace=True, axis=1) >>> df.head() Identifier Place of Publication Date of Publication \ 0 206 London 1879 [1878] 1 216 London; Virtue & Yorston 1868 2 218 London 1869 3 472 London 1851 4 480 London 1857 Publisher Title \ 0 S. Tinsley & Co. Walter Forbes. [A novel.] By A. A 1 Virtue & Co. All for Greed. [A novel. The dedication signed... 2 Bradbury, Evans & Co. Love the Avenger. By the author ofAll for Gr... 3 James Darling Welsh Sketches, chiefly ecclesiastical, to the... 4 Wertheim & Macintosh [The World in which I live, and my place in it... Author Flickr URL 0 A. A. http://www.flickr.com/photos/britishlibrary/ta... 1 A., A. A. http://www.flickr.com/photos/britishlibrary/ta... 2 A., A. A. http://www.flickr.com/photos/britishlibrary/ta... 3 A., E. S. http://www.flickr.com/photos/britishlibrary/ta... 4 A., E. S. http://www.flickr.com/photos/britishlibrary/ta... >>>4

Hàng đầu tiên đó trông khá vô dụng. Vì vậy, có thể bỏ nó:

>>> to_drop = ['Edition Statement', ... 'Corporate Author', ... 'Corporate Contributors', ... 'Former owner', ... 'Engraver', ... 'Contributors', ... 'Issuance type', ... 'Shelfmarks'] >>> df.drop(to_drop, inplace=True, axis=1) >>> df.head() Identifier Place of Publication Date of Publication \ 0 206 London 1879 [1878] 1 216 London; Virtue & Yorston 1868 2 218 London 1869 3 472 London 1851 4 480 London 1857 Publisher Title \ 0 S. Tinsley & Co. Walter Forbes. [A novel.] By A. A 1 Virtue & Co. All for Greed. [A novel. The dedication signed... 2 Bradbury, Evans & Co. Love the Avenger. By the author ofAll for Gr... 3 James Darling Welsh Sketches, chiefly ecclesiastical, to the... 4 Wertheim & Macintosh [The World in which I live, and my place in it... Author Flickr URL 0 A. A. http://www.flickr.com/photos/britishlibrary/ta... 1 A., A. A. http://www.flickr.com/photos/britishlibrary/ta... 2 A., A. A. http://www.flickr.com/photos/britishlibrary/ta... 3 A., E. S. http://www.flickr.com/photos/britishlibrary/ta... 4 A., E. S. http://www.flickr.com/photos/britishlibrary/ta... >>>5

Cái đó tốt hơn. Bây giờ cho phép đổi tên một số cột:

>>> to_drop = ['Edition Statement', ... 'Corporate Author', ... 'Corporate Contributors', ... 'Former owner', ... 'Engraver', ... 'Contributors', ... 'Issuance type', ... 'Shelfmarks'] >>> df.drop(to_drop, inplace=True, axis=1) >>> df.head() Identifier Place of Publication Date of Publication \ 0 206 London 1879 [1878] 1 216 London; Virtue & Yorston 1868 2 218 London 1869 3 472 London 1851 4 480 London 1857 Publisher Title \ 0 S. Tinsley & Co. Walter Forbes. [A novel.] By A. A 1 Virtue & Co. All for Greed. [A novel. The dedication signed... 2 Bradbury, Evans & Co. Love the Avenger. By the author ofAll for Gr... 3 James Darling Welsh Sketches, chiefly ecclesiastical, to the... 4 Wertheim & Macintosh [The World in which I live, and my place in it... Author Flickr URL 0 A. A. http://www.flickr.com/photos/britishlibrary/ta... 1 A., A. A. http://www.flickr.com/photos/britishlibrary/ta... 2 A., A. A. http://www.flickr.com/photos/britishlibrary/ta... 3 A., E. S. http://www.flickr.com/photos/britishlibrary/ta... 4 A., E. S. http://www.flickr.com/photos/britishlibrary/ta... >>>6

Tốt hơn nhiều! Lưu ý rằng chúng tôi đã thêm các bài viết vào các cột lặp lại của chúng tôi (vàng, bạc, đồng) để mỗi cột là duy nhất trong khung dữ liệu.

Và do đó kết thúc hướng dẫn về dữ liệu làm sạch với Python.

Python và Pydoc

Một số thứ tuyệt vời về tài liệu mã Python ở đây:

>>> to_drop = ['Edition Statement', ... 'Corporate Author', ... 'Corporate Contributors', ... 'Former owner', ... 'Engraver', ... 'Contributors', ... 'Issuance type', ... 'Shelfmarks'] >>> df.drop(to_drop, inplace=True, axis=1) >>> df.head() Identifier Place of Publication Date of Publication \ 0 206 London 1879 [1878] 1 216 London; Virtue & Yorston 1868 2 218 London 1869 3 472 London 1851 4 480 London 1857 Publisher Title \ 0 S. Tinsley & Co. Walter Forbes. [A novel.] By A. A 1 Virtue & Co. All for Greed. [A novel. The dedication signed... 2 Bradbury, Evans & Co. Love the Avenger. By the author ofAll for Gr... 3 James Darling Welsh Sketches, chiefly ecclesiastical, to the... 4 Wertheim & Macintosh [The World in which I live, and my place in it... Author Flickr URL 0 A. A. http://www.flickr.com/photos/britishlibrary/ta... 1 A., A. A. http://www.flickr.com/photos/britishlibrary/ta... 2 A., A. A. http://www.flickr.com/photos/britishlibrary/ta... 3 A., E. S. http://www.flickr.com/photos/britishlibrary/ta... 4 A., E. S. http://www.flickr.com/photos/britishlibrary/ta... >>>7

Hãy làm sạch các nhận xét mã để >>> df.loc[216] Place of Publication London; Virtue & Yorston Date of Publication 1868 Publisher Virtue & Co. Title All for Greed. [A novel. The dedication signed... Author A., A. A. Flickr URL http://www.flickr.com/photos/britishlibrary/ta... Name: 216, dtype: object >>>4 hiển thị sạch sẽ:

>>> to_drop = ['Edition Statement', ... 'Corporate Author', ... 'Corporate Contributors', ... 'Former owner', ... 'Engraver', ... 'Contributors', ... 'Issuance type', ... 'Shelfmarks'] >>> df.drop(to_drop, inplace=True, axis=1) >>> df.head() Identifier Place of Publication Date of Publication \ 0 206 London 1879 [1878] 1 216 London; Virtue & Yorston 1868 2 218 London 1869 3 472 London 1851 4 480 London 1857 Publisher Title \ 0 S. Tinsley & Co. Walter Forbes. [A novel.] By A. A 1 Virtue & Co. All for Greed. [A novel. The dedication signed... 2 Bradbury, Evans & Co. Love the Avenger. By the author ofAll for Gr... 3 James Darling Welsh Sketches, chiefly ecclesiastical, to the... 4 Wertheim & Macintosh [The World in which I live, and my place in it... Author Flickr URL 0 A. A. http://www.flickr.com/photos/britishlibrary/ta... 1 A., A. A. http://www.flickr.com/photos/britishlibrary/ta... 2 A., A. A. http://www.flickr.com/photos/britishlibrary/ta... 3 A., E. S. http://www.flickr.com/photos/britishlibrary/ta... 4 A., E. S. http://www.flickr.com/photos/britishlibrary/ta... >>>8

Tài liệu tham khảo

Dữ liệu gọn gàng

>>> to_drop = ['Edition Statement', ... 'Corporate Author', ... 'Corporate Contributors', ... 'Former owner', ... 'Engraver', ... 'Contributors', ... 'Issuance type', ... 'Shelfmarks'] >>> df.drop(to_drop, inplace=True, axis=1) >>> df.head() Identifier Place of Publication Date of Publication \ 0 206 London 1879 [1878] 1 216 London; Virtue & Yorston 1868 2 218 London 1869 3 472 London 1851 4 480 London 1857 Publisher Title \ 0 S. Tinsley & Co. Walter Forbes. [A novel.] By A. A 1 Virtue & Co. All for Greed. [A novel. The dedication signed... 2 Bradbury, Evans & Co. Love the Avenger. By the author ofAll for Gr... 3 James Darling Welsh Sketches, chiefly ecclesiastical, to the... 4 Wertheim & Macintosh [The World in which I live, and my place in it... Author Flickr URL 0 A. A. http://www.flickr.com/photos/britishlibrary/ta... 1 A., A. A. http://www.flickr.com/photos/britishlibrary/ta... 2 A., A. A. http://www.flickr.com/photos/britishlibrary/ta... 3 A., E. S. http://www.flickr.com/photos/britishlibrary/ta... 4 A., E. S. http://www.flickr.com/photos/britishlibrary/ta... >>>9

read_csv

>>> df['Identifier'].is_unique True >>>0

read_pickle

>>> df['Identifier'].is_unique True >>>1

làm rơi

>>> df['Identifier'].is_unique True >>>2

to_csv

>>> df['Identifier'].is_unique True >>>3

to_pickle

>>> df['Identifier'].is_unique True >>>4

Làm

  • Recrephrase DOC Nhận xét để phù hợp với >>> df.loc[216] Place of Publication London; Virtue & Yorston Date of Publication 1868 Publisher Virtue & Co. Title All for Greed. [A novel. The dedication signed... Author A., A. A. Flickr URL http://www.flickr.com/photos/britishlibrary/ta... Name: 216, dtype: object >>>5
  • Thêm kết quả khảo sát từ khảo sát của Crowdflower 2016
  • Pickle mọi thứ thay vì viết tệp đầu ra

Tín dụng

Lấy cảm hứng từ hướng dẫn tuyệt vời này:

>>> df['Identifier'].is_unique True >>>5

Tôi đã thực sự ấn tượng bởi chất lượng của các hướng dẫn Python thực sự.

Python có được sử dụng để làm sạch dữ liệu không?

Tầm quan trọng của Python, Numpy và Pandas, cả hai thư viện Python (có nghĩa là các công cụ được lập trình sẵn) là những công cụ được lựa chọn giữa các nhà khoa học dữ liệu khi nói đến làm sạch dữ liệu, chuẩn bị và phân tích khác.both Python libraries (meaning pre-programmed toolsets) are the tools of choice amongst data scientists when it comes to data cleaning, prep, and other analysis.

Làm thế nào để bạn thực hành làm sạch dữ liệu trong Python?

Chúng tôi sẽ bao gồm những điều sau:..
Thả các cột không cần thiết trong một khung dữ liệu ..
Thay đổi chỉ mục của một khung dữ liệu ..
Sử dụng. Phương pháp str () để làm sạch các cột ..
Sử dụng DataFrame. applicationMap () hàm để làm sạch toàn bộ bộ dữ liệu, yếu tố khôn ngoan ..
Đổi tên các cột thành một bộ nhãn dễ nhận biết hơn ..
Bỏ qua các hàng không cần thiết trong tệp CSV ..

Thư viện Python nào được sử dụng để làm sạch dữ liệu?

Klib.KLIB là một gói Python nguồn mở để nhập, làm sạch và phân tích.Đây là gói một cửa được sử dụng để dễ dàng hiểu dữ liệu của bạn và tiền xử lý.. Klib is an open-source Python package for importing, cleaning, and analyzing. It is a one-stop package used for easily understanding your data and preprocessing.

Làm thế nào để pyspark làm sạch dữ liệu?

Cài đặt Spark trên Google Colab và tải bộ dữ liệu trong pyspark.Thay đổi kiểu dữ liệu cột, loại bỏ khoảng trắng và thả bản sao.Loại bỏ các cột có giá trị null cao hơn ngưỡng.Nhóm, tổng hợp và tạo bảng trục.Change column datatype, remove whitespaces and drop duplicates. Remove columns with Null values higher than a threshold. Group, aggregate and create pivot tables.

Chủ đề