一個帥氣的boy,你可以叫我Love And Program
個人主頁:Love And Program的個人主頁
如果對你有幫助的話希望三連支持一下博主

python是目前非常火爆的語言,其在人工智能、數據分析領域都占有一席之地,無論是學習還是工作,都會給你帶來相當大的幫助.我在這給大家 推薦一個快速提升自己的網站牛客網,他們現在的IT題庫內容很豐富,屬於國內做的很好的了,可以在下圖中看見裡面試題應有盡有,最最最重要的裡面的資源全部免費!!!(親測全免費,寫題解還可以得小禮物)歡迎大家自助練習🥰🥰
系列專欄鏈接:
Python快速刷題網站——牛客網 數據分析篇(一)
Python快速刷題網站——牛客網 數據分析篇(二)
Python快速刷題網站——牛客網 數據分析篇(三)
Python快速刷題網站——牛客網 數據分析篇(四)
Learn how to use it in this chapterpandas快速選取 所需目標

Summary of important information:如何輸出Python這門語言
輸出結果如下圖所示:

那麼問題來了,How to extract specificallyPython?
前面我們提到了iloc()和loc()to find the corresponding row,So can we use these two functions to find itlanguage 中的 Python?很明顯,是可以的.
(Let's create a table)
import numpy as np
import pandas as pd
data= pd.DataFrame({
"Nowcoder_ID":['first','second','third','fourth'],
"Level":[1,2,3,2],
"Language":['Python','CPP','Python','C/C#'],
"Achievement_value":[8711,13,999999,2],
"Num_of_exercise":[500,2,32,222],
"Graduate_year":[np.nan,np.nan ,np.nan,'7']
})
# Nowcoder_ID Level Language Achievement_value Num_of_exercise Graduate_year
#0 first 1 Python 8711 500 NaN
#1 second 2 CPP 13 2 NaN
#2 third 3 Python 999999 32 NaN
#3 fourth 2 C/C# 2 222 7
這時我們選擇data中的Language列篩選,選中Python字段,代碼如下:
print(data.loc[data['Language']=='Python'])

很明顯Python被篩選出來,那我們用iloc函數試試
data.iloc[:,data['Language']=='Python']
# NotImplementedError: iLocation based boolean indexing on an integer type is not available
我們需要想想,loc()函數是按標簽取數據,而iloc()函數是按索引位置選擇數據,只接受 整型參數!!,所以iloc()是不行的.Is there no other way?
有的!用query()函數!!Query by Boolean expressiondataframe中的列,Specifically used to filter data.
(注意:Please knock it yourself,Otherwise, new knowledge cannot be learned,Not to mention memorizing these functions)
data.query("Language == 'Python' ")

Finally, the code for this question is attached鏈接:DA6 Check which users of Niuke.com use itPython
import pandas as pd
Nowcoder = pd.read_csv('Nowcoder.csv',sep=',',dtype=object)
# print(Nowcoder.loc[Nowcoder['Language']=='Python'])
# print(Nowcoder[Nowcoder['Language']=='Python'])
print(Nowcoder.query('Language=="Python"'))
Just keep practicing your ability to write code,to keep these functions in mind,and use it consciously.