Hướng dẫn data manipulation with python datacamp answers - thao tác dữ liệu với câu trả lời của dấu dữ liệu python

Permalink

Show

chính

Chuyển nhánh/thẻ

Không thể tải các nhánh

Không có gì để hiển thị

{{refname}}

Tên đã được sử dụng

Một thẻ đã tồn tại với tên chi nhánh được cung cấp. Nhiều lệnh GIT chấp nhận cả tên thẻ và tên chi nhánh, vì vậy việc tạo nhánh này có thể gây ra hành vi bất ngờ. Bạn có chắc là bạn muốn tạo chi nhánh này?

Đi nộp

  • Đi nộp
  • Sao chép đường dẫn
  • Sao chép permalink

Không thể lấy lại những người đóng góp tại thời điểm này

8269 dòng (8269 SLOC) 368 KB 368 KB

Đổ lỗi

Mở trong máy tính để bàn GitHub

  • Mở với máy tính để bàn
  • Xem thô
  • Xem đổ lỗi

Xin lỗi, có lỗi xảy ra. Tải lại?

Xin lỗi, chúng tôi không thể hiển thị tệp này.

Xin lỗi, tệp này không hợp lệ nên nó không thể được hiển thị.

# Create indiv_per_10k col as homeless individuals per 10k state pop
homelessness["indiv_per_10k"] = 10000 * homelessness["individuals"] / homelessness["state_pop"]

# Subset rows for indiv_per_10k greater than 20
high_homelessness = homelessness[homelessness['indiv_per_10k']>20]

# Sort high_homelessness by descending indiv_per_10k
high_homelessness_srt = high_homelessness.sort_values('indiv_per_10k', ascending=False)

# From high_homelessness_srt, select the state and indiv_per_10k cols
result = high_homelessness_srt[['state','indiv_per_10k']]

# See the result
print(result)
9,
# Print the head of the sales DataFrame
print(sales.head())

# Print the info about the sales DataFrame
print(sales.info())

# Print the mean of weekly_sales
print(sales['weekly_sales'].mean())

# Print the median of weekly_sales
print(sales['weekly_sales'].median())
0

Loại bỏ các giá trị bị thiếu

Thay thế các giá trị bị thiếu

Tạo DataFrames

  • Danh sách từ điển
  • # Select the individuals column
    individuals = homelessness['individuals']
    
    # Select the state and family_members columns
    state_fam = homelessness[['state','family_members']]
    
    # Select only the individuals and state columns, in that order
    ind_state = homelessness[['individuals','state']]
    
    7
  • Từ điển danh sách
  • Đọc và viết CSVS

# Print the head of the homelessness data
print(homelessness.head())

# Print information about homelessness
print(homelessness.info())

# Print the shape of homelessness
print(homelessness.shape)

# Print a description of homelessness
print(homelessness.describe())

CSV đến DataFrame

  • DataFrame đến CSV
  • Thao tác dữ liệu với Python là gì?
  • Pandas là một thư viện phân tích dữ liệu nguồn mở và phân tích dữ liệu được viết bằng Python. Gấu trúc cung cấp cho bạn các cấu trúc dữ liệu và chức năng để làm việc trên dữ liệu có cấu trúc một cách liền mạch. Tên gấu trúc đề cập đến dữ liệu bảng điều khiển, có nghĩa là một bộ dữ liệu có cấu trúc. Pandas có hai lớp chính để làm việc, DataFrame và Sê -ri.

# Import pandas using the alias pd
import pandas as pd

# Print a 2D NumPy array of the values in homelessness.
print(homelessness.values)

# Print the column names of homelessness
print(homelessness.columns)

# Print the row index of homelessness
print(homelessness.index)

Kích thước và ứng dụng thường có sự khác biệt về chi phí giữa bơ có kích thước lớn hơn và nhỏ hơn, với kích thước lớn hơn thường đắt hơn. Các loại bơ được sử dụng rộng rãi nhất trong dịch vụ thực phẩm là 48 và 60, với 48 số lượng là sự lựa chọn nổi bật.

Làm cách nào để nhận được một DataFrame từ một cột?

# Sort homelessness by individual
homelessness_ind = homelessness.sort_values('individuals')

# Sort homelessness by descending family members
homelessness_fam = homelessness.sort_values('family_members',ascending=False)

# Sort homelessness by region, then descending family members
homelessness_reg_fam = homelessness.sort_values(['region','family_members'], ascending = [True, False])

Chọn các cột dựa trên tên của chúng Đây là cách cơ bản nhất để chọn một cột duy nhất từ ​​DataFrame, chỉ cần đặt tên chuỗi của cột vào dấu ngoặc. Trả lại một loạt gấu trúc. Vượt qua danh sách trong dấu ngoặc cho phép bạn chọn nhiều cột cùng một lúc.

# Select the individuals column
individuals = homelessness['individuals']

# Select the state and family_members columns
state_fam = homelessness[['state','family_members']]

# Select only the individuals and state columns, in that order
ind_state = homelessness[['individuals','state']]

Pandas Datacamp là gì?

# Filter for rows where individuals is greater than 10000
ind_gt_10k = homelessness[homelessness['individuals']>10000]

# Filter for rows where region is Mountain
mountain_reg = homelessness[homelessness['region']=="Mountain"]

# Filter for rows where family_members is less than 1000 
# and region is Pacific
fam_lt_1k_pac = homelessness[(homelessness['family_members']<1000) & (homelessness['region']=="Pacific")]

Pandas là thư viện Python phổ biến nhất thế giới, được sử dụng cho tất cả mọi thứ, từ thao tác dữ liệu đến phân tích dữ liệu. Trong khóa học này, bạn sẽ tìm hiểu cách thao tác với DataFrames, khi bạn trích xuất, lọc và chuyển đổi bộ dữ liệu trong thế giới thực để phân tích. Sử dụng gấu trúc, bạn sẽ khám phá tất cả các khái niệm khoa học dữ liệu cốt lõi.

Cơ sở trên DataCamp.

# Subset for rows in South Atlantic or Mid-Atlantic regions
south_mid_atlantic = homelessness[(homelessness['region']=="South Atlantic") | (homelessness['region']=="Mid-Atlantic")]

# The Mojave Desert states
canu = ["California", "Arizona", "Nevada", "Utah"]

# Filter for rows in the Mojave Desert states
mojave_homelessness = homelessness[homelessness['state'].isin(canu)]

DataFrames

# Add total col as sum of individuals and family_members
homelessness['total'] = homelessness['individuals'] + homelessness['family_members']

# Add p_individuals col as proportion of individuals
homelessness['p_individuals'] = homelessness['individuals'] / homelessness['total']

# See the result
print(homelessness)

Combo-attack!

# Create indiv_per_10k col as homeless individuals per 10k state pop
homelessness["indiv_per_10k"] = 10000 * homelessness["individuals"] / homelessness["state_pop"]

# Subset rows for indiv_per_10k greater than 20
high_homelessness = homelessness[homelessness['indiv_per_10k']>20]

# Sort high_homelessness by descending indiv_per_10k
high_homelessness_srt = high_homelessness.sort_values('indiv_per_10k', ascending=False)

# From high_homelessness_srt, select the state and indiv_per_10k cols
result = high_homelessness_srt[['state','indiv_per_10k']]

# See the result
print(result)

Giới thiệu DataFrames

Kiểm tra một khung dữ liệu

# Filter for rows where individuals is greater than 10000
ind_gt_10k = homelessness[homelessness['individuals']>10000]

# Filter for rows where region is Mountain
mountain_reg = homelessness[homelessness['region']=="Mountain"]

# Filter for rows where family_members is less than 1000 
# and region is Pacific
fam_lt_1k_pac = homelessness[(homelessness['family_members']<1000) & (homelessness['region']=="Pacific")]
1 trả về một vài hàng đầu tiên (đầu của người đứng đầu của DataFrame).

# Print the head of the sales DataFrame
print(sales.head())

# Print the info about the sales DataFrame
print(sales.info())

# Print the mean of weekly_sales
print(sales['weekly_sales'].mean())

# Print the median of weekly_sales
print(sales['weekly_sales'].median())

# Filter for rows where individuals is greater than 10000
ind_gt_10k = homelessness[homelessness['individuals']>10000]

# Filter for rows where region is Mountain
mountain_reg = homelessness[homelessness['region']=="Mountain"]

# Filter for rows where family_members is less than 1000 
# and region is Pacific
fam_lt_1k_pac = homelessness[(homelessness['family_members']<1000) & (homelessness['region']=="Pacific")]
2 hiển thị thông tin về từng cột, chẳng hạn như kiểu dữ liệu và số lượng giá trị bị thiếu.

# Print the maximum of the date column
print(sales['date'].max())
> 2012-10-26 00:00:00

# Print the minimum of the date column
print(sales['date'].min())
> 2010-02-05 00:00:00

# Filter for rows where individuals is greater than 10000
ind_gt_10k = homelessness[homelessness['individuals']>10000]

# Filter for rows where region is Mountain
mountain_reg = homelessness[homelessness['region']=="Mountain"]

# Filter for rows where family_members is less than 1000 
# and region is Pacific
fam_lt_1k_pac = homelessness[(homelessness['family_members']<1000) & (homelessness['region']=="Pacific")]
3 Trả về số lượng hàng và cột của DataFrame.

# Filter for rows where individuals is greater than 10000
ind_gt_10k = homelessness[homelessness['individuals']>10000]

# Filter for rows where region is Mountain
mountain_reg = homelessness[homelessness['region']=="Mountain"]

# Filter for rows where family_members is less than 1000 
# and region is Pacific
fam_lt_1k_pac = homelessness[(homelessness['family_members']<1000) & (homelessness['region']=="Pacific")]
4 Tính toán một vài thống kê tóm tắt cho mỗi cột.

# Import pandas using the alias pd
import pandas as pd

# Print a 2D NumPy array of the values in homelessness.
print(homelessness.values)

# Print the column names of homelessness
print(homelessness.columns)

# Print the row index of homelessness
print(homelessness.index)
0

Các bộ phận của một khung dữ liệu

# Filter for rows where individuals is greater than 10000
ind_gt_10k = homelessness[homelessness['individuals']>10000]

# Filter for rows where region is Mountain
mountain_reg = homelessness[homelessness['region']=="Mountain"]

# Filter for rows where family_members is less than 1000 
# and region is Pacific
fam_lt_1k_pac = homelessness[(homelessness['family_members']<1000) & (homelessness['region']=="Pacific")]
5: Một mảng giá trị hai chiều.

# Import pandas using the alias pd
import pandas as pd

# Print a 2D NumPy array of the values in homelessness.
print(homelessness.values)

# Print the column names of homelessness
print(homelessness.columns)

# Print the row index of homelessness
print(homelessness.index)
1

# Filter for rows where individuals is greater than 10000 ind_gt_10k = homelessness[homelessness['individuals']>10000] # Filter for rows where region is Mountain mountain_reg = homelessness[homelessness['region']=="Mountain"] # Filter for rows where family_members is less than 1000 # and region is Pacific fam_lt_1k_pac = homelessness[(homelessness['family_members']<1000) & (homelessness['region']=="Pacific")] 6: Một chỉ mục của các cột: Tên cột.

# Filter for rows where individuals is greater than 10000
ind_gt_10k = homelessness[homelessness['individuals']>10000]

# Filter for rows where region is Mountain
mountain_reg = homelessness[homelessness['region']=="Mountain"]

# Filter for rows where family_members is less than 1000 
# and region is Pacific
fam_lt_1k_pac = homelessness[(homelessness['family_members']<1000) & (homelessness['region']=="Pacific")]
7: Một chỉ mục cho các hàng: số hàng hoặc tên hàng.

# Import pandas using the alias pd
import pandas as pd

# Print a 2D NumPy array of the values in homelessness.
print(homelessness.values)

# Print the column names of homelessness
print(homelessness.columns)

# Print the row index of homelessness
print(homelessness.index)
2

Sắp xếp và tập hợp

# Import pandas using the alias pd
import pandas as pd

# Print a 2D NumPy array of the values in homelessness.
print(homelessness.values)

# Print the column names of homelessness
print(homelessness.columns)

# Print the row index of homelessness
print(homelessness.index)
3

Sắp xếp các hàng

# Subset for rows in South Atlantic or Mid-Atlantic regions
south_mid_atlantic = homelessness[(homelessness['region']=="South Atlantic") | (homelessness['region']=="Mid-Atlantic")]

# The Mojave Desert states
canu = ["California", "Arizona", "Nevada", "Utah"]

# Filter for rows in the Mojave Desert states
mojave_homelessness = homelessness[homelessness['state'].isin(canu)]
4

Các cột tập hợp

# Import pandas using the alias pd
import pandas as pd

# Print a 2D NumPy array of the values in homelessness.
print(homelessness.values)

# Print the column names of homelessness
print(homelessness.columns)

# Print the row index of homelessness
print(homelessness.index)
4

Hàng hóa hàng

# Import pandas using the alias pd
import pandas as pd

# Print a 2D NumPy array of the values in homelessness.
print(homelessness.values)

# Print the column names of homelessness
print(homelessness.columns)

# Print the row index of homelessness
print(homelessness.index)
5

Hàng hóa hàng theo các biến phân loại

# Import pandas using the alias pd
import pandas as pd

# Print a 2D NumPy array of the values in homelessness.
print(homelessness.values)

# Print the column names of homelessness
print(homelessness.columns)

# Print the row index of homelessness
print(homelessness.index)
6

# Filter for rows where individuals is greater than 10000 ind_gt_10k = homelessness[homelessness['individuals']>10000] # Filter for rows where region is Mountain mountain_reg = homelessness[homelessness['region']=="Mountain"] # Filter for rows where family_members is less than 1000 # and region is Pacific fam_lt_1k_pac = homelessness[(homelessness['family_members']<1000) & (homelessness['region']=="Pacific")] 8, # Filter for rows where individuals is greater than 10000 ind_gt_10k = homelessness[homelessness['individuals']>10000] # Filter for rows where region is Mountain mountain_reg = homelessness[homelessness['region']=="Mountain"] # Filter for rows where family_members is less than 1000 # and region is Pacific fam_lt_1k_pac = homelessness[(homelessness['family_members']<1000) & (homelessness['region']=="Pacific")] 9

Cột mới

Tổng hợp dữ liệu

# Import pandas using the alias pd
import pandas as pd

# Print a 2D NumPy array of the values in homelessness.
print(homelessness.values)

# Print the column names of homelessness
print(homelessness.columns)

# Print the row index of homelessness
print(homelessness.index)
7

Thống kê tóm tắt

Trung bình và trung bình

  • Tóm tắt ngày
  • Tóm tắt hiệu quả

# Import pandas using the alias pd
import pandas as pd

# Print a 2D NumPy array of the values in homelessness.
print(homelessness.values)

# Print the column names of homelessness
print(homelessness.columns)

# Print the row index of homelessness
print(homelessness.index)
8

Cắt và lập chỉ mục

# Add total col as sum of individuals and family_members
homelessness['total'] = homelessness['individuals'] + homelessness['family_members']

# Add p_individuals col as proportion of individuals
homelessness['p_individuals'] = homelessness['individuals'] / homelessness['total']

# See the result
print(homelessness)
2,
# Add total col as sum of individuals and family_members
homelessness['total'] = homelessness['individuals'] + homelessness['family_members']

# Add p_individuals col as proportion of individuals
homelessness['p_individuals'] = homelessness['individuals'] / homelessness['total']

# See the result
print(homelessness)
3

Chỉ số rõ ràng

Cài đặt và xóa các chỉ mục

# Import pandas using the alias pd
import pandas as pd

# Print a 2D NumPy array of the values in homelessness.
print(homelessness.values)

# Print the column names of homelessness
print(homelessness.columns)

# Print the row index of homelessness
print(homelessness.index)
9

Cắt và tập hợp với .loc và .iloc

# Sort homelessness by individual
homelessness_ind = homelessness.sort_values('individuals')

# Sort homelessness by descending family members
homelessness_fam = homelessness.sort_values('family_members',ascending=False)

# Sort homelessness by region, then descending family members
homelessness_reg_fam = homelessness.sort_values(['region','family_members'], ascending = [True, False])
0

Đặt các chỉ mục đa cấp

# Sort homelessness by individual
homelessness_ind = homelessness.sort_values('individuals')

# Sort homelessness by descending family members
homelessness_fam = homelessness.sort_values('family_members',ascending=False)

# Sort homelessness by region, then descending family members
homelessness_reg_fam = homelessness.sort_values(['region','family_members'], ascending = [True, False])
1

Sắp xếp theo các giá trị chỉ mục

# Sort homelessness by individual
homelessness_ind = homelessness.sort_values('individuals')

# Sort homelessness by descending family members
homelessness_fam = homelessness.sort_values('family_members',ascending=False)

# Sort homelessness by region, then descending family members
homelessness_reg_fam = homelessness.sort_values(['region','family_members'], ascending = [True, False])
2

Cắt và tập hợp với .loc và .iloc

Đặt các chỉ mục đa cấp

Sắp xếp theo các giá trị chỉ mục

  • Cắt giá trị chỉ số
  • So với danh sách cắt lát, có một vài điều cần nhớ.
  • Bạn chỉ có thể cắt một chỉ mục nếu chỉ mục được sắp xếp (sử dụng
    # Add total col as sum of individuals and family_members
    homelessness['total'] = homelessness['individuals'] + homelessness['family_members']
    
    # Add p_individuals col as proportion of individuals
    homelessness['p_individuals'] = homelessness['individuals'] / homelessness['total']
    
    # See the result
    print(homelessness)
    
    4).
  • Để cắt ở cấp độ bên ngoài,
    # Add total col as sum of individuals and family_members
    homelessness['total'] = homelessness['individuals'] + homelessness['family_members']
    
    # Add p_individuals col as proportion of individuals
    homelessness['p_individuals'] = homelessness['individuals'] / homelessness['total']
    
    # See the result
    print(homelessness)
    
    5 và
    # Add total col as sum of individuals and family_members
    homelessness['total'] = homelessness['individuals'] + homelessness['family_members']
    
    # Add p_individuals col as proportion of individuals
    homelessness['p_individuals'] = homelessness['individuals'] / homelessness['total']
    
    # See the result
    print(homelessness)
    
    6 có thể là chuỗi.

# Sort homelessness by individual
homelessness_ind = homelessness.sort_values('individuals')

# Sort homelessness by descending family members
homelessness_fam = homelessness.sort_values('family_members',ascending=False)

# Sort homelessness by region, then descending family members
homelessness_reg_fam = homelessness.sort_values(['region','family_members'], ascending = [True, False])
3

Để cắt lát ở cấp độ bên trong,
# Add total col as sum of individuals and family_members
homelessness['total'] = homelessness['individuals'] + homelessness['family_members']

# Add p_individuals col as proportion of individuals
homelessness['p_individuals'] = homelessness['individuals'] / homelessness['total']

# See the result
print(homelessness)
5 và
# Add total col as sum of individuals and family_members
homelessness['total'] = homelessness['individuals'] + homelessness['family_members']

# Add p_individuals col as proportion of individuals
homelessness['p_individuals'] = homelessness['individuals'] / homelessness['total']

# See the result
print(homelessness)
6 nên là bộ dữ liệu.

# Sort homelessness by individual
homelessness_ind = homelessness.sort_values('individuals')

# Sort homelessness by descending family members
homelessness_fam = homelessness.sort_values('family_members',ascending=False)

# Sort homelessness by region, then descending family members
homelessness_reg_fam = homelessness.sort_values(['region','family_members'], ascending = [True, False])
4

Nếu bạn chuyển một lát duy nhất cho
# Add total col as sum of individuals and family_members
homelessness['total'] = homelessness['individuals'] + homelessness['family_members']

# Add p_individuals col as proportion of individuals
homelessness['p_individuals'] = homelessness['individuals'] / homelessness['total']

# See the result
print(homelessness)
9, nó sẽ cắt các hàng.

Cắt theo cả hai hướng

# Sort homelessness by individual
homelessness_ind = homelessness.sort_values('individuals')

# Sort homelessness by descending family members
homelessness_fam = homelessness.sort_values('family_members',ascending=False)

# Sort homelessness by region, then descending family members
homelessness_reg_fam = homelessness.sort_values(['region','family_members'], ascending = [True, False])
5

Lát chuỗi thời gian

Thêm cột

# Create indiv_per_10k col as homeless individuals per 10k state pop
homelessness["indiv_per_10k"] = 10000 * homelessness["individuals"] / homelessness["state_pop"]

# Subset rows for indiv_per_10k greater than 20
high_homelessness = homelessness[homelessness['indiv_per_10k']>20]

# Sort high_homelessness by descending indiv_per_10k
high_homelessness_srt = high_homelessness.sort_values('indiv_per_10k', ascending=False)

# From high_homelessness_srt, select the state and indiv_per_10k cols
result = high_homelessness_srt[['state','indiv_per_10k']]

# See the result
print(result)
0 vào chỉ mục, sau đó sử dụng
# Add total col as sum of individuals and family_members
homelessness['total'] = homelessness['individuals'] + homelessness['family_members']

# Add p_individuals col as proportion of individuals
homelessness['p_individuals'] = homelessness['individuals'] / homelessness['total']

# See the result
print(homelessness)
9 để thực hiện tập hợp con. Điều quan trọng cần nhớ là giữ ngày của bạn ở định dạng ISO 8601, nghĩa là
# Create indiv_per_10k col as homeless individuals per 10k state pop
homelessness["indiv_per_10k"] = 10000 * homelessness["individuals"] / homelessness["state_pop"]

# Subset rows for indiv_per_10k greater than 20
high_homelessness = homelessness[homelessness['indiv_per_10k']>20]

# Sort high_homelessness by descending indiv_per_10k
high_homelessness_srt = high_homelessness.sort_values('indiv_per_10k', ascending=False)

# From high_homelessness_srt, select the state and indiv_per_10k cols
result = high_homelessness_srt[['state','indiv_per_10k']]

# See the result
print(result)
2.

# Sort homelessness by individual
homelessness_ind = homelessness.sort_values('individuals')

# Sort homelessness by descending family members
homelessness_fam = homelessness.sort_values('family_members',ascending=False)

# Sort homelessness by region, then descending family members
homelessness_reg_fam = homelessness.sort_values(['region','family_members'], ascending = [True, False])
6

Tập hợp theo số hàng/cột

Điều này được thực hiện bằng cách sử dụng
# Create indiv_per_10k col as homeless individuals per 10k state pop
homelessness["indiv_per_10k"] = 10000 * homelessness["individuals"] / homelessness["state_pop"]

# Subset rows for indiv_per_10k greater than 20
high_homelessness = homelessness[homelessness['indiv_per_10k']>20]

# Sort high_homelessness by descending indiv_per_10k
high_homelessness_srt = high_homelessness.sort_values('indiv_per_10k', ascending=False)

# From high_homelessness_srt, select the state and indiv_per_10k cols
result = high_homelessness_srt[['state','indiv_per_10k']]

# See the result
print(result)
3 và như
# Add total col as sum of individuals and family_members
homelessness['total'] = homelessness['individuals'] + homelessness['family_members']

# Add p_individuals col as proportion of individuals
homelessness['p_individuals'] = homelessness['individuals'] / homelessness['total']

# See the result
print(homelessness)
9, nó có thể mất hai đối số để cho phép bạn tập hợp con theo hàng và cột.

Làm việc với bảng xoay vòng

# Sort homelessness by individual
homelessness_ind = homelessness.sort_values('individuals')

# Sort homelessness by descending family members
homelessness_fam = homelessness.sort_values('family_members',ascending=False)

# Sort homelessness by region, then descending family members
homelessness_reg_fam = homelessness.sort_values(['region','family_members'], ascending = [True, False])
7

Nhiệt độ xoay theo thành phố và năm

Bạn có thể truy cập các thành phần của một ngày (năm, tháng và ngày) bằng cách sử dụng mã của Mẫu

# Create indiv_per_10k col as homeless individuals per 10k state pop
homelessness["indiv_per_10k"] = 10000 * homelessness["individuals"] / homelessness["state_pop"]

# Subset rows for indiv_per_10k greater than 20
high_homelessness = homelessness[homelessness['indiv_per_10k']>20]

# Sort high_homelessness by descending indiv_per_10k
high_homelessness_srt = high_homelessness.sort_values('indiv_per_10k', ascending=False)

# From high_homelessness_srt, select the state and indiv_per_10k cols
result = high_homelessness_srt[['state','indiv_per_10k']]

# See the result
print(result)
5. Ví dụ: thành phần tháng là
# Create indiv_per_10k col as homeless individuals per 10k state pop
homelessness["indiv_per_10k"] = 10000 * homelessness["individuals"] / homelessness["state_pop"]

# Subset rows for indiv_per_10k greater than 20
high_homelessness = homelessness[homelessness['indiv_per_10k']>20]

# Sort high_homelessness by descending indiv_per_10k
high_homelessness_srt = high_homelessness.sort_values('indiv_per_10k', ascending=False)

# From high_homelessness_srt, select the state and indiv_per_10k cols
result = high_homelessness_srt[['state','indiv_per_10k']]

# See the result
print(result)
6 và thành phần năm là
# Create indiv_per_10k col as homeless individuals per 10k state pop
homelessness["indiv_per_10k"] = 10000 * homelessness["individuals"] / homelessness["state_pop"]

# Subset rows for indiv_per_10k greater than 20
high_homelessness = homelessness[homelessness['indiv_per_10k']>20]

# Sort high_homelessness by descending indiv_per_10k
high_homelessness_srt = high_homelessness.sort_values('indiv_per_10k', ascending=False)

# From high_homelessness_srt, select the state and indiv_per_10k cols
result = high_homelessness_srt[['state','indiv_per_10k']]

# See the result
print(result)
7.

# Sort homelessness by individual
homelessness_ind = homelessness.sort_values('individuals')

# Sort homelessness by descending family members
homelessness_fam = homelessness.sort_values('family_members',ascending=False)

# Sort homelessness by region, then descending family members
homelessness_reg_fam = homelessness.sort_values(['region','family_members'], ascending = [True, False])
8

Tập hợp các bảng xoay vòng

# Sort homelessness by individual
homelessness_ind = homelessness.sort_values('individuals')

# Sort homelessness by descending family members
homelessness_fam = homelessness.sort_values('family_members',ascending=False)

# Sort homelessness by region, then descending family members
homelessness_reg_fam = homelessness.sort_values(['region','family_members'], ascending = [True, False])
9

Một bảng Pivot chỉ là một khung dữ liệu với các chỉ mục được sắp xếp. Kết hợp cắt # Add total col as sum of individuals and family_members homelessness['total'] = homelessness['individuals'] + homelessness['family_members'] # Add p_individuals col as proportion of individuals homelessness['p_individuals'] = homelessness['individuals'] / homelessness['total'] # See the result print(homelessness) 9 + thường hữu ích.

Tính toán trên bàn xoay

Tạo và trực quan hóa các khung dữ liệu

# Select the individuals column
individuals = homelessness['individuals']

# Select the state and family_members columns
state_fam = homelessness[['state','family_members']]

# Select only the individuals and state columns, in that order
ind_state = homelessness[['individuals','state']]
0

Trực quan hóa dữ liệu của bạn

# Select the individuals column
individuals = homelessness['individuals']

# Select the state and family_members columns
state_fam = homelessness[['state','family_members']]

# Select only the individuals and state columns, in that order
ind_state = homelessness[['individuals','state']]
1

Kích thước bơ nào là phổ biến nhất?

# Select the individuals column
individuals = homelessness['individuals']

# Select the state and family_members columns
state_fam = homelessness[['state','family_members']]

# Select only the individuals and state columns, in that order
ind_state = homelessness[['individuals','state']]
2

Thay đổi doanh số theo thời gian

# Select the individuals column
individuals = homelessness['individuals']

# Select the state and family_members columns
state_fam = homelessness[['state','family_members']]

# Select only the individuals and state columns, in that order
ind_state = homelessness[['individuals','state']]
3

Cung và cầu bơ

Giá của bơ thông thường so với hữu cơ

Giá trị bị mất

# Select the individuals column
individuals = homelessness['individuals']

# Select the state and family_members columns
state_fam = homelessness[['state','family_members']]

# Select only the individuals and state columns, in that order
ind_state = homelessness[['individuals','state']]
4

Tìm các giá trị bị thiếu

# Print the head of the sales DataFrame
print(sales.head())

# Print the info about the sales DataFrame
print(sales.info())

# Print the mean of weekly_sales
print(sales['weekly_sales'].mean())

# Print the median of weekly_sales
print(sales['weekly_sales'].median())
1

# Select the individuals column
individuals = homelessness['individuals']

# Select the state and family_members columns
state_fam = homelessness[['state','family_members']]

# Select only the individuals and state columns, in that order
ind_state = homelessness[['individuals','state']]
5

# Create indiv_per_10k col as homeless individuals per 10k state pop
homelessness["indiv_per_10k"] = 10000 * homelessness["individuals"] / homelessness["state_pop"]

# Subset rows for indiv_per_10k greater than 20
high_homelessness = homelessness[homelessness['indiv_per_10k']>20]

# Sort high_homelessness by descending indiv_per_10k
high_homelessness_srt = high_homelessness.sort_values('indiv_per_10k', ascending=False)

# From high_homelessness_srt, select the state and indiv_per_10k cols
result = high_homelessness_srt[['state','indiv_per_10k']]

# See the result
print(result)
9,
# Print the head of the sales DataFrame
print(sales.head())

# Print the info about the sales DataFrame
print(sales.info())

# Print the mean of weekly_sales
print(sales['weekly_sales'].mean())

# Print the median of weekly_sales
print(sales['weekly_sales'].median())
0

# Select the individuals column
individuals = homelessness['individuals']

# Select the state and family_members columns
state_fam = homelessness[['state','family_members']]

# Select only the individuals and state columns, in that order
ind_state = homelessness[['individuals','state']]
6

Loại bỏ các giá trị bị thiếu

Thay thế các giá trị bị thiếu

Tạo DataFrames

Danh sách từ điển

# Select the individuals column
individuals = homelessness['individuals']

# Select the state and family_members columns
state_fam = homelessness[['state','family_members']]

# Select only the individuals and state columns, in that order
ind_state = homelessness[['individuals','state']]
8

# Select the individuals column individuals = homelessness['individuals'] # Select the state and family_members columns state_fam = homelessness[['state','family_members']] # Select only the individuals and state columns, in that order ind_state = homelessness[['individuals','state']] 7

Từ điển danh sách

# Select the individuals column
individuals = homelessness['individuals']

# Select the state and family_members columns
state_fam = homelessness[['state','family_members']]

# Select only the individuals and state columns, in that order
ind_state = homelessness[['individuals','state']]
9

Đọc và viết CSVS

# Filter for rows where individuals is greater than 10000
ind_gt_10k = homelessness[homelessness['individuals']>10000]

# Filter for rows where region is Mountain
mountain_reg = homelessness[homelessness['region']=="Mountain"]

# Filter for rows where family_members is less than 1000 
# and region is Pacific
fam_lt_1k_pac = homelessness[(homelessness['family_members']<1000) & (homelessness['region']=="Pacific")]
0

Thao tác dữ liệu với Python là gì?

Pandas là một thư viện phân tích dữ liệu nguồn mở và phân tích dữ liệu được viết bằng Python. Gấu trúc cung cấp cho bạn các cấu trúc dữ liệu và chức năng để làm việc trên dữ liệu có cấu trúc một cách liền mạch. Tên gấu trúc đề cập đến dữ liệu bảng điều khiển, có nghĩa là một bộ dữ liệu có cấu trúc. Pandas có hai lớp chính để làm việc, DataFrame và Sê -ri.. Pandas provide you with data structures and functions to work on structured data seamlessly. The name Pandas refer to “Panel Data”, which means a structured dataset. Pandas have two main classes to work on, DataFrame and Series.

Kích thước bơ nào là phổ biến nhất?

Kích thước và ứng dụng thường có sự khác biệt về chi phí giữa bơ có kích thước lớn hơn và nhỏ hơn, với kích thước lớn hơn thường đắt hơn.Các loại bơ được sử dụng rộng rãi nhất trong dịch vụ thực phẩm là 48 và 60, với 48 số lượng là sự lựa chọn nổi bật.48 and 60 count, with 48 count being the prominent choice.

Làm cách nào để nhận được một DataFrame từ một cột?

Chọn các cột dựa trên tên của chúng Đây là cách cơ bản nhất để chọn một cột duy nhất từ DataFrame, chỉ cần đặt tên chuỗi của cột vào dấu ngoặc.Trả lại một loạt gấu trúc.Vượt qua danh sách trong dấu ngoặc cho phép bạn chọn nhiều cột cùng một lúc.put the string name of the column in brackets. Returns a pandas series. Passing a list in the brackets lets you select multiple columns at the same time.

Pandas Datacamp là gì?

Pandas là thư viện Python phổ biến nhất thế giới, được sử dụng cho tất cả mọi thứ, từ thao tác dữ liệu đến phân tích dữ liệu.Trong khóa học này, bạn sẽ tìm hiểu cách thao tác với DataFrames, khi bạn trích xuất, lọc và chuyển đổi bộ dữ liệu trong thế giới thực để phân tích.Sử dụng gấu trúc, bạn sẽ khám phá tất cả các khái niệm khoa học dữ liệu cốt lõi.the world's most popular Python library, used for everything from data manipulation to data analysis. In this course, you'll learn how to manipulate DataFrames, as you extract, filter, and transform real-world datasets for analysis. Using pandas you'll explore all the core data science concepts.