Chipotle資料分析 知識點彙總

2021-10-08 14:54:42 字數 2575 閱讀 7102

一、資料集資訊

import pandas as pd

import numpy as np

import matplotlib.pyplot as plt

chipo = pd.read_csv(

'/users/desktop/十套python練習/exercise_data/chipotle.tsv'

, sep =

'\t'

)chipo.head(10)

#顯示前十行

chipo.shape[0]

#顯示行數

chipp.shape[1]

#顯示列數

chipo.columns#列印列名稱

chipo.index#列印索引

二、分類(groupby)

#提取數量和名稱兩行,按照itemname進行分類,再對quantity進行聚合操作sum

#as_index表示是否將item_name列的各項作為index,若為true,則下圖的chickenbowl等在最左邊index列

#建立新的一行subtotal,填入每一行的總花費並保留兩位小數

chipo[

'subtotal']=

round

(chipo[item_price]

* chipo[quantity],2

)#取花費列subtotal和order列,根據order進行分組,對相同單數的**進行相加,得到每一單的總價,最後再對總價求平均值

chipo[

['subtotal'

,'order_id']]

.groupby(

'order_id'

).agg()[

'subtotal'

].mean(

)

df.groupby()和df.agg()

例:

df = pd.dataframe(

根據國家分組

根據國家、收入分組

根據國家分組後對剩下的income和age分別求mean、max、min

根據國家分組,對剩下的age求min、mean、max,對income求min、max(用列表形式表示)

資料分析簡單知識點(numpy)

資料分析基本概念 明確思路 資料收集 分布式爬蟲實戰 資料處理 資料分析 資料展現 常用的收集途徑 公開資訊,外部資料庫,自有資料庫,調查問卷,客戶資料 資料清洗 可讀性,完整性,唯一性,權威性及合法性 常見的資料型別 1,類別型資料 1 取值種類 2 每類取值的分布 2,數值型變數 1 極值和分位...

資料分析之SQL常問知識點

資料分析之sql常問知識點 一 insert into select 語句 與 select into from 語句 語句形式 insert into table2 field1,field2,select value1,value2,value3,from table1要求目標表table2 必...

python資料分析基礎知識點一

map函式用於遍歷序列。對序列中每個元素進行操作,最終獲取新的序列 如 li 11,22,33 new list map lambda a a 100,li list new list 輸出結果 111,122,133 如 li 11,22,33 s1 1,2,3 new list map lamb...