104學習

Data Analysis

Data Analysis
關注
邀請朋友
邀請朋友

Line

Facebook

複製連結

取消
「Data Analysis:主要負責收集、整理及分析公司內外部數據,以支持經營決策和策略規劃。此角色致力於發掘數據中的洞見,協助提升業務運作效率與效益。需要具備強大的數據分析能力,熟悉統計工具和資料庫管理,並具備良好的數據視覺化技巧。有效的跨部門協作及溝通能力是必備,因需定期向管理層報告分析結果並提出建議。面對台灣快速變化的市場環境,應能敏銳掌握趨勢並靈活應對挑戰,提升企業競爭力。」
關於教室
關注人數 1 人
104人力銀行從職缺中挑選出常見技能所成立的官方教室,提供大家進行共學互動。
學習主持人
持續分享知識,
有機會成為官方教室主持人
教室標籤
關於教室
關注人數 1 人
104人力銀行從職缺中挑選出常見技能所成立的官方教室,提供大家進行共學互動。
學習主持人
持續分享知識,
有機會成為官方教室主持人
教室標籤
Hi~ 歡迎分享學習資源,有學習問題可匿名向Giver發問!
我要分享
我要提問

Data Analysis 學習推薦

不知如何開始嗎? 先進行技能挑戰吧~

技能挑戰:初級
目前等級:未達初級
1 人已通過「初級」測驗,通過率100%,和學習一起探索知識、增強能力!
我要挑戰
Mike Ku

Learn Code With Mike品牌創辦人

2021/10/27

Pandas DataFrame處理雙維度資料方法(4)
Q:如何取得Pandas DataFrame資料?
1.head():取得最前面的n筆資料,並且會回傳一個新的Pandas DataFrame資料集,如下範例:
grades = {
"name": ["Mike", "Sherry", "Cindy", "John"],
"math": [80, 75, 93, 86],
"chinese": [63, 90, 85, 70]
}
df = pd.DataFrame(grades)
new_df = df.head(2)
print(new_df) #取得最前面的兩筆資料
2.tail():取得最後面的n筆資料,並且會回傳一個新的Pandas DataFrame資料集,如下範例:
grades = {
"name": ["Mike", "Sherry", "Cindy", "John"],
"math": [80, 75, 93, 86],
"chinese": [63, 90, 85, 70]
}
df = pd.DataFrame(grades)
new_df = df.tail(3)
print(new_df) #取得最後面的三筆資料
3.中括號[]:在中括號中指定「欄位名稱」或「資料索引值」,來取得所需的資料集,如下範例:
grades = {
"name": ["Mike", "Sherry", "Cindy", "John"],
"math": [80, 75, 93, 86],
"chinese": [63, 90, 85, 70]
}
df = pd.DataFrame(grades)
print(df[["name"]]) #取得單一欄位資料(型別為DataFrame)
print(df[["name", "chinese"]]) #取得多欄位資料(型別為DataFrame)
print(df[0:3]) #取得索引值0~2的資料
4.at[資料索引值,欄位名稱]:利用資料索引值及欄位名稱來取得「單一值」,如下範例:
grades = {
"name": ["Mike", "Sherry", "Cindy", "John"],
"math": [80, 75, 93, 86],
"chinese": [63, 90, 85, 70]
}
df = pd.DataFrame(grades)
print(df.at[1, "math"]) #利用at()方法取得索引值為1的math欄位資料
5.iat[資料索引值,欄位順序]:利用資料索引值及欄位順序來取得「單一值」,如下範例:
grades = {
"name": ["Mike", "Sherry", "Cindy", "John"],
"math": [80, 75, 93, 86],
"chinese": [63, 90, 85, 70]
}
df = pd.DataFrame(grades)
print(df.iat[1, 0]) #取得索引值為1的第一個欄位資料"
5.loc[資料索引值,欄位名稱]:利用資料索引值及欄位名稱來取得「資料集」,如下範例:
grades = {
"name": ["Mike", "Sherry", "Cindy", "John"],
"math": [80, 75, 93, 86],
"chinese": [63, 90, 85, 70]
}
df = pd.DataFrame(grades)
print(df.loc[[1, 3], ["name", "chinese"]]) #取得資料索引值為1和3的name及chinese欄位資料集
6.iloc[資料索引值,欄位順序]:利用資料索引值及欄位順序來取得「資料集」,如下範例:
grades = {
"name": ["Mike", "Sherry", "Cindy", "John"],
"math": [80, 75, 93, 86],
"chinese": [63, 90, 85, 70]
}
df = pd.DataFrame(grades)
print(df.iloc[[1, 3], [0, 2]]) #取得資料索引值為1和3的第一個及第三個欄位資料集
如果想要學習更多的Python應用教學,歡迎前往Learn Code With Mike( https://www.learncodewithmike.com/2020/11/python-pandas-dataframe-tutorial.html )網站觀看更多精彩內容。
看更多
2 0 425 0
Mike Ku

Learn Code With Mike品牌創辦人

2021/10/27

Pandas DataFrame處理雙維度資料方法(3)
Q:如何刪除Pandas DataFrame資料
1.drop(欄位名稱串列,axis=1):刪除指定欄位名稱的欄位,並且會回傳一個新的Pandas DataFrame資料集,如下範例:
grades = {
"name": ["Mike", "Sherry", "Cindy", "John"],
"math": [80, 75, 93, 86],
"chinese": [63, 90, 85, 70]
}
df = pd.DataFrame(grades)
new_df = df.drop(["math"], axis=1)
print("刪除math欄位")
print(new_df)
2.drop(資料索引串列,axis=0):刪除指定資料索引的資料,並且會回傳一個新的Pandas DataFrame資料集,如下範例:
grades = {
"name": ["Mike", "Sherry", "Cindy", "John"],
"math": [80, 75, 93, 86],
"chinese": [63, 90, 85, 70]
}
df = pd.DataFrame(grades)
new_df = df.drop([0, 3], axis=0) # 刪除第一筆及第四筆資料
print("刪除第一筆及第四筆資料")
print(new_df)
3.dropna():刪除含有NaN或空值的資料,並且會回傳一個新的Pandas DataFrame資料集,在進行資料清理的時候非常實用,如下範例:
grades = {
"name": ["Mike", "Sherry", np.NaN, "John"],
"math": [80, 75, 93, 86],
"chinese": [63, 90, 85, 70]
}
df = pd.DataFrame(grades)
new_df = df.dropna()
print("刪除空值後的df")
print(new_df)
4.drop_duplicates():刪除重複的資料,並且會回傳一個新的Pandas DataFrame資料集,同樣最常應用在資料清理的時候,如下範例:
grades = {
"name": ["Mike", "Mike", "Cindy", "John"],
"city": ["Taipei", "Taipei", "Kaohsiung", "Taichung"],
"math": [80, 80, 93, 86],
"chinese": [80, 80, 93, 86]
}
df = pd.DataFrame(grades)
new_df = df.drop_duplicates()
print("刪除重複值後的df")
print(new_df)
Q:如何篩選Pandas DataFrame資料
通常在處理大量的資料集時,有很高的機率會需要利用條件式來篩選所需的資料,這時候就可以利用中括號[]存取欄位來進行資料篩選,如下範例:
grades = {
"name": ["Mike", "Sherry", "Cindy", "John"],
"math": [80, 75, 93, 86],
"chinese": [63, 90, 85, 70]
}
df = pd.DataFrame(grades)
print("篩選math大於80的資料集")
print(df[df["math"] > 80])
另一個最常見的資料篩選情境,就是找出包含特定值的資料集,這時候可以利用Pandas DataFrame的isin()方法(Method)來達成,如下範例:
grades = {
"name": ["Mike", "Sherry", "Cindy", "John"],
"math": [80, 75, 93, 86],
"chinese": [63, 90, 85, 70]
}
df = pd.DataFrame(grades)
print("篩選name欄位包含John的資料集")
print(df[df["name"].isin(["John"])])
如果想要學習更多的Python應用教學,歡迎前往Learn Code With Mike( https://www.learncodewithmike.com/2020/11/python-pandas-dataframe-tutorial.html )網站觀看更多精彩內容。
看更多
2 0 2483 0
Mike Ku

Learn Code With Mike品牌創辦人

2021/10/27

Pandas DataFrame處理雙維度資料方法(2)
Q:如何新增Pandas DataFrame資料?
1.insert():在指定的欄位位置新增欄位資料,如下範例:
grades = {
"name": ["Mike", "Sherry", "Cindy", "John"],
"math": [80, 75, 93, 86],
"chinese": [63, 90, 85, 70]
}
df = pd.DataFrame(grades)
df.insert(2, column="engilsh", value=[88, 72, 74, 98])
print("在第三欄的地方新增一個欄位資料")
print(df)
2.append():新增一筆或一列的資料,透過傳入字典來指定各欄位的值,並且會回傳一個新的Pandas DataFrame資料集,如下範例:
grades = {
"name": ["Mike", "Sherry", "Cindy", "John"],
"math": [80, 75, 93, 86],
"chinese": [63, 90, 85, 70]
}
df = pd.DataFrame(grades)
new_df = df.append({
"name": "Henry",
"math": 60,
"chinese": 62
}, ignore_index=True)
print("新增一筆資料")
print(new_df)
3.concat():利用合併多個Pandas DataFrame的方式來新增資料,並且會回傳一個新的Pandas DataFrame資料集,如下範例:
grades = {
"name": ["Mike", "Sherry", "Cindy", "John"],
"math": [80, 75, 93, 86],
"chinese": [63, 90, 85, 70]
}
df1 = pd.DataFrame(grades)
df2 = pd.DataFrame({
"name": ["Henry"],
"math": [60],
"chinese": [62]
})
new_df = pd.concat([df1, df2], ignore_index=True)
print("合併df來新增資料")
print(new_df)
Q:如何排序Pandas DataFrame資料?
1.sort_index():依照索引值來進行排序,並且會回傳一個新的Pandas DataFrame資料集,如下範例:
grades = {
"name": ["Mike", "Sherry", "Cindy", "John"],
"math": [80, 75, 93, 86],
"chinese": [63, 90, 85, 70]
}
df = pd.DataFrame(grades)
df.index = ["s3", "s1", "s4", "s2"]
new_df = df.sort_index(ascending=True)
print("遞增排序")
print(new_df)
new_df = df.sort_index(ascending=False)
print("遞減排序")
print(new_df)
2.sort_values():依照欄位內容來進行排序,並且會回傳一個新的Pandas DataFrame資料集,下面範例以math欄位內容來進行排序:
grades = {
"name": ["Mike", "Sherry", "Cindy", "John"],
"math": [80, 75, 93, 86],
"chinese": [63, 90, 85, 70]
}
df = pd.DataFrame(grades)
new_df = df.sort_values(["math"], ascending=True)
print("遞增排序")
print(new_df)
new_df = df.sort_values(["math"], ascending=False)
print("遞減排序")
print(new_df)
如果想要學習更多的Python應用教學,歡迎前往Learn Code With Mike( https://www.learncodewithmike.com/2020/11/python-pandas-dataframe-tutorial.html )網站觀看更多精彩內容。
看更多
3 0 14692 1
你可能感興趣的教室