pandas之Seris和DataFrame

pandas是一個強大的python工具包,提供了大量處理數據的函數和方法,用于處理數據和分析數據。

使用pandas之前需要先安裝pandas包,并通過import pandas as pd導入。

?

一、系列Series

Seris為帶標簽的一維數組,標簽即為索引。

1.Series的創建

Seris創建的方法:s = pd.Seris(obj , index=' ***' , name='***')

Seris創建時如果不通過參數指定name,名稱默認為None,并不是=前面的變量名稱s。

①通過字典創建

通過字典創建Seris,字典的key即為索引。如果字典的key有重復,創建Seris時會取最后出現的一個值。

dic = {'name':'Alice','age':23,'age':20,'age':25,'hobby':'dance'}
s = pd.Series(dic,name='dic_Seris')
print(s)
# name     Alice
# age         25
# hobby    dance
# Name: dic_Seris, dtype: object
通過字典創建Seris

?

②通過一維數組、列表或元組創建

通過這種方法,如果不指定索引index,默認為從0開始的整數;如果指定index,index的數量必須與Seris的元素個數保持一致,否則會報錯。

arr = np.arange(1,6)
s1 = pd.Series(arr)
s2 = pd.Series(arr,index=list('abcde'),name='iter_Seris')
print(s1.name,s2.name)
print(s1)
print('-------------')
print(s2)
# None iter_Seris
# 0    1
# 1    2
# 2    3
# 3    4
# 4    5
# dtype: int32
# -------------
# a    1
# b    2
# c    3
# d    4
# e    5
# Name: iter_Seris, dtype: int32
通過一維數組、列表或元組創建Seris

?

③通過標量創建

?通過標量創建時,參數obj為一個固定的值,表示Seris中元素的值,此時必須指定index,index的個數表示元素個數。

s = pd.Series('hi',index=list('abc'),name='s_Seris')
print(s)
# a    hi
# b    hi
# c    hi
# Name: s_Seris, dtype: object
通過標量創建Seris

?

2.Series的索引

①下標索引

下標索引從0開始,-1表示最后一個元素,通過[m:n]切片包括m不包括n。Seris中的每一個元素類型為<class 'numpy.***'>

還可以通過[[ m,n,x]]獲取下標為m、n、x的值,列表和元組沒有該用法。

s = pd.Series([1,2,3,4,5],index=list('abcde'))
print(s[1],type(s[1]))
print(s[-2])
print(s[1:3])
print(s[[0,4]])
# 2 <class 'numpy.int64'>
# 4
# b    2
# c    3
# dtype: int64
# a    1
# e    5
# dtype: int64
Seris下標索引

?

②標簽索引

與下標索引不同的是,標簽通過[m:n]切片時包含m也包含n。也可以通過[[ m,n,x]]獲取標簽為m、n和x的值

s = pd.Series([1,2,3,4,5],index=list('abcde'))
print(s['b'])
print(s['c':'d'])
print(s[['a','e']])
# 2
# c    3
# d    4
# dtype: int64
# a    1
# e    5
# dtype: int64
Seris標簽索引

?

注意,如果Seris的標簽也為整數時,會出現混亂,因此不建議自定義數字為標簽索引。

s = pd.Series([1,2,3,4,5],index=[1,2,3,4,5])
print(s)
print('------------')
print(s[3])
print('------------')
print(s[2:4])
# 1    1
# 2    2
# 3    3
# 4    4
# 5    5
# dtype: int64
# ------------
# 3
# ------------
# 3    3
# 4    4
# dtype: int64
View Code

?

③布爾索引

s = pd.Series([1,2,3,4,5],index=list('abcde'))
m = s > 3
print(m)
print(s[m])
# a    False
# b    False
# c    False
# d     True
# e     True
# dtype: bool
# d    4
# e    5
# dtype: int64
Seris布爾值索引

?

3.Seris查看和常用方法

①head()和tail()

參數默認為5,表示查看前5個和后5個,可指定參數。

s = pd.Series([1,2,3,4,5,6,7,8,9,10])
print(s.head(2))
print(s.tail((3)))
# 0    1
# 1    2
# dtype: int64
# 7     8
# 8     9
# 9    10
# dtype: int64
head()和tail()

?

②tolist()(也可寫作to_list())

將Seris轉化為列表

s = pd.Series(np.random.randint(1,10,10))
print(s.tolist())
# [3, 8, 8, 9, 8, 2, 2, 7, 7, 7]

?

③reindex(index , fill_value=NaN)

reindex會生成一個新的Seris,對于參數index,如果在原Seris的index中存在則保留,不存在則將值填充為fill_value指定的值,fill_value默認為NaN

arr = np.arange(1,6)
s1 = pd.Series(arr,index = list('abcde'))
s2 =s1.reindex(['a','d','f','h'],fill_value=0)
print(s1)
print(s2)
# a    1
# b    2
# c    3
# d    4
# e    5
# dtype: int32
# a    1
# d    4
# f    0
# h    0
# dtype: int32
reindex()

?

?④+和-

Seris與單個值的加法和減法,是對Seris的每個元素進行操作。

兩個Seris的加法和減法,對兩者index相同的數值做加法和減法,不相同的部分index都保留,值默認為NaN。

s1 = pd.Series(np.arange(1,4),index = list('abc'))
s2 = pd.Series(np.arange(5,8),index = list('bcd'))
print(s1+s2)
print('--------')
print(s2-s1)
print('--------')
print(s1+10)
# a    NaN
# b    7.0
# c    9.0
# d    NaN
# dtype: float64
# --------
# a    NaN
# b    3.0
# c    3.0
# d    NaN
# dtype: float64
# --------
# a    11
# b    12
# c    13
# dtype: int32
Seris的加法和減法

?

?⑤元素的添加

直接通過標簽方式添加元素(通過下標方式添加報超出索引錯誤),修改原Seris。

s = pd.Series(np.arange(1,4),index = list('abc'))
# s[3] = 10
s['p'] = 15
print(s)
# a     1
# b     2
# c     3
# p    15
# dtype: int64
Seris添加元素

?

s1.appeng(s2),生成一個新的Seris,不修改s1和s2

s1 = pd.Series(np.arange(1,3),index = list('ab'))
s2 = pd.Series(np.arange(3,5),index = list('mn'))
a = s1.append(s2)
print(s1)
print(s2)
print(a)
# a    1
# b    2
# dtype: int32
# m    3
# n    4
# dtype: int32
# a    1
# b    2
# m    3
# n    4
# dtype: int32
append()

?

⑥元素的刪除drop()

用法:drop(index,inplace = False),表示刪除原Seris中索引為參數index的值,默認刪除的內容會生成一個新的Seris且不改變原Seris,如果指定Inplace = True則會直接修改原Seris。

s1 = pd.Series(np.arange(1,4),index = list('abc'))
s2 = s1.drop(['a','c'])
print(s1)
print(s2)
s3 = pd.Series(np.arange(5,8),index = list('lmn'))
s4 = s3.drop('m',inplace=True)
print(s3)
print(s4)
# a    1
# b    2
# c    3
# dtype: int32
# b    2
# dtype: int32
# l    5
# n    7
drop()刪除元素

?返回頂部

二、數據幀DataFrame

DataFrame是一個表格型的數據結構,是一組帶有標簽的二維數組,DataFrame是pandas中最常用的一種數據結構。創建一個DataFrame為df,則

df.index表示行索引,df.columns表示列索引,df.values表示實際的值。

dic = {'name':['alice','Bob','Jane'],'age':[23,26,25]}
df = pd.DataFrame(dic)
print(df)
print(type(df))
print(df.index)
print(df.columns)
print(df.values)
#     name  age
# 0  alice   23
# 1    Bob   26
# 2   Jane   25
# <class 'pandas.core.frame.DataFrame'>
# RangeIndex(start=0, stop=3, step=1)
# Index(['name', 'age'], dtype='object')
# [['alice' 23]
#  ['Bob' 26]
#  ['Jane' 25]]
DataFrame數據示例

?

1.DataFrame的創建

①通過字典、或者由字典組成的列表創建

通過這種方法,字典的key就是列索引,行索引默認為從0開始的整數。

dic1 = [{'name':'Alice','age':23},{'name':'Bob','age':26},{'name':'Jane','age':25}]
dic2 = {'name':['alice','Bob','Jane'],'age':[23,26,25]}
df1 = pd.DataFrame(dic1)
df2 = pd.DataFrame(dic2)
print(df1)
print('---------------')
# print(pd.DataFrame(df1,columns=['name','age']))
print(df2)
#    age   name
# 0   23  Alice
# 1   26    Bob
# 2   25   Jane
# ---------------
#     name  age
# 0  alice   23
# 1    Bob   26
# 2   Jane   25
通過列表或字典創建DataFrame

?

創建時可通過index指定行索引,但是索引的個數必須要與DataFrame的行數保持一致,否則會報錯。

也可以通過columns指定列索引,列索引的個數可以不與DataFrame的列數保持一致,索引相同的部分保留,原字典或列表中多余的部分去除,columns中多余的部分保留并填充值為NaN

dic = {'name':['alice','Bob','Jane'],'age':[23,26,25]}
df1 = pd.DataFrame(dic,columns=['name','hobby'])
df2 = pd.DataFrame(dic,index=['a','b','c'])
print(df1)
print(df2)
#    name hobby
# 0  alice   NaN
# 1    Bob   NaN
# 2   Jane   NaN
#     name  age
# a  alice   23
# b    Bob   26
# c   Jane   25
指定行索引和列索引

?

②通過Seris創建

通過Seris創建時,Seris的長度可以不一致,DataFrame會取最長的Seris,并將不足的部分填充為NaN

dic1 = {'one':pd.Series(np.arange(2)),'two':pd.Series(np.arange(3))}
dic2 = {'one':pd.Series(np.arange(2),index=['a','b']),'two':pd.Series(np.arange(3),index = ['a','b','c'])}
print(pd.DataFrame(dic1))
print('------------')
print(pd.DataFrame(dic2))
#    one  two
# 0  0.0    0
# 1  1.0    1
# 2  NaN    2
# ------------
#    one  two
# a  0.0    0
# b  1.0    1
# c  NaN    2
通過Seris創建DataFrame

?

③通過二維數組創建

方法:DataFrame(arr,index=‘***’? ,columns=‘***’),如果不指定index和columns,默認都是從0開始的整數,如果指定則index和columns的長度必須與二維數據的行數和列數相同,否則會報錯。

arr = np.arange(12).reshape(3,4)
df = pd.DataFrame(arr,index=['a','b','c'],columns=['col1','col2','col3','col4'])
print(df)
#    col1  col2  col3  col4
# a     0     1     2     3
# b     4     5     6     7
# c     8     9    10    11
通過二維數組創建DataFrame

?

④通過嵌套字典創建?

通過這種方法創建,字典的外層key為列索引,內層key為行索引。

dic = {'Chinese':{'Alice':92,'Bob':95,'Jane':93},'Math':{'Alice':96,'Bob':98,'Jane':95}}
print(pd.DataFrame(dic))
#        Chinese  Math
# Alice       92    96
# Bob         95    98
# Jane        93    95
通過嵌套字典創建DataFrame

?

2.DataFrame的索引

可通過.values直接獲取不帶index和column的內容部分,結果為一個二維數組。

arr = np.arange(12).reshape(3,4)
df = pd.DataFrame(arr,index = ['a','b','c'],columns = ['one','two','three','four'])
print(df.values)
# [[ 0  1  2  3]
#  [ 4  5  6  7]
#  [ 8  9 10 11]]
.values獲取內容部分

?

①列索引

單列索引直接使用df['列索引']即可,數據類型為Seris,名稱為列索引,index為原DataFrame的index;

多列索引通過df[['列索引1','列索引2',...]],結果為DataFrame,columns為指定的索引,index為原DataFrame的index。

arr = np.arange(12).reshape(3,4)
df = pd.DataFrame(arr,index = ['a','b','c'],columns = ['one','two','three','four'])
print(df)
print('-------------')
print(df['one'],type(df['one']))
print('-------------')
print(df[['one','three']])
#    one  two  three  four
# a    0    1      2     3
# b    4    5      6     7
# c    8    9     10    11
# -------------
# a    0
# b    4
# c    8
# Name: one, dtype: int32 <class 'pandas.core.series.Series'>
# -------------
#    one  three
# a    0      2
# b    4      6
# c    8     10
DataFrame列索引

?

②行索引

單行索引通過df.loc['行索引']實現,數據類型為Seris,名稱為行索引,index為原DataFrame的columns;

多行索引通過df.loc[['行索引1','行索引2',...]],結果為DataFrame,columns為原DataFrame的columns,index為的指定的行索引。

arr = np.arange(12).reshape(3,4)
df = pd.DataFrame(arr,index = ['a','b','c'],columns = ['one','two','three','four'])
print(df.loc['a'],type(df.loc['a']))
print(df.loc[['a','c']])
# one      0
# two      1
# three    2
# four     3
# Name: a, dtype: int32 <class 'pandas.core.series.Series'>
#    one  two  three  four
# a    0    1      2     3
# c    8    9     10    11
DataFrame行索引

?

行索引也可以使用iloc[],loc[]使用標簽作為行索引,iloc[ ]使用下標(即第幾行)作為索引

arr = np.arange(12).reshape(3,4)
df = pd.DataFrame(arr,index = ['a','b','c'],columns = ['one','two','three','four'])
print(df.iloc[1],type(df.iloc[1]))
print(df.iloc[[0,2]])
# one      4
# two      5
# three    6
# four     7
# Name: b, dtype: int32 <class 'pandas.core.series.Series'>
#    one  two  three  four
# a    0    1      2     3
# c    8    9     10    11
DataFrame的iloc[]行索引

?

③單元格和塊索引

單元格的索引有三種方式:df['列索引'].loc['行索引']、df.loc['行索引']['列索引']、df.loc['行索引','列索引']

塊索引:df[['列索引1','列索引2'...]].loc[['行索引1','行索引2'...]]、df.loc[['行索引1','行索引2'...]][['列索引1','列索引2'...]]、df.loc[['行索引1','行索引2'...]],[['列索引1','列索引2'...]]

arr = np.arange(12).reshape(3,4)
df = pd.DataFrame(arr,index = ['a','b','c'],columns = ['one','two','three','four'])
print(df)
print('--------------------------')
print(df['two'].loc['b'] , df.loc['b']['two'] , df.loc['b','two'])
print('--------------------------')
print(df.loc[['a','c'],['one','four']])
#    one  two  three  four
# a    0    1      2     3
# b    4    5      6     7
# c    8    9     10    11
# --------------------------
# 5 5 5
# --------------------------
#    one  four
# a    0     3
# c    8    11
DataFrame單元格和塊索引

?

④布爾索引

如果對DataFrame進行單列布爾索引,結果會顯示列中值為True所在的行。

arr = np.arange(12).reshape(3,4)
df = pd.DataFrame(arr,index = ['a','b','c'],columns = ['one','two','three','four'])
m1= df['one']>5
print(df)
print('------------------------')
print(m1) #索引c對應的值為True
print('------------------------')
print(df[m1])  #顯示索引c所在的行,包括所有列
#   one  two  three  four
# a    0    1      2     3
# b    4    5      6     7
# c    8    9     10    11
# ------------------------
# a    False
# b    False
# c     True
# Name: one, dtype: bool
# ------------------------
#    one  two  three  four
# c    8    9     10    11
DataFrame單列布爾索引

?

如果對多列或整個DataFrame進行布爾索引,結果是一個與DataFrame結構相同的DataFrame,其中索引列中符合條件的以實際值顯示,不符合條件的以NaN顯示。

arr = np.arange(12).reshape(3,4)
df = pd.DataFrame(arr,index = ['a','b','c'],columns = ['one','two','three','four'])
m1 = df[['one','three']] > 5
print(m1)
print(df[m1])   #列one、three中符合條件的顯示實際值,其他都顯示為NaN
#      one  three
# a  False  False
# b  False   True
# c   True   True
#    one  two  three  four
# a  NaN  NaN    NaN   NaN
# b  NaN  NaN    6.0   NaN
# c  8.0  NaN   10.0   NaN
DataFrame多列布爾索引

?

df = pd.DataFrame(arr,index = ['a','b','c'],columns = ['one','two','three','four'])
m = df >5
print(m)
print(df[m])
#     one    two  three   four
# a  False  False  False  False
# b  False  False   True   True
# c   True   True   True   True
#    one  two  three  four
# a  NaN  NaN    NaN   NaN
# b  NaN  NaN    6.0   7.0
# c  8.0  9.0   10.0  11.0
整個DataFrame布爾索引

?

(對行做布爾索引會報錯pandas.core.indexing.IndexingError: Unalignable boolean Series provided as indexer (index of the boolean Series and of the indexed object do not match)

?

3.DataFrame的常用方法

①.T轉置

DataFrame轉置會將原columns變為index,原index變為columns,并且修改原DataFrame會修改轉置后的DataFrame,修改轉置后的DataFrame也會修改原DataFrame。

arr = np.arange(12).reshape(3,4)
df1 = pd.DataFrame(arr,index = ['a','b','c'],columns = ['one','two','three','four'])
df2 = df1.T
df1.loc['a','one'] = 100
print(df1)
print(df2)
df2.loc['two','b'] = 500
print(df1)
print(df2)
#    one  two  three  four
# a  100    1      2     3
# b    4    5      6     7
# c    8    9     10    11
#          a  b   c
# one    100  4   8
# two      1  5   9
# three    2  6  10
# four     3  7  11
#    one  two  three  four
# a  100    1      2     3
# b    4  500      6     7
# c    8    9     10    11
#          a    b   c
# one    100    4   8
# two      1  500   9
# three    2    6  10
# four     3    7  11
DataFrame轉置

?

②添加與修改

增加列:df['新列索引'] = [***],元素的個數必須與DataFrame的行數相同,否則會報錯。

增加行:df.loc['新行索引'] = [***],元素的個數必須與DataFrame的列數相同,否則會報錯。

修改DataFrame直接通過上一節單元格或塊索引的方式獲得單元格或塊,再修改即可。

arr = np.arange(12).reshape(3,4)
df = pd.DataFrame(arr,index = ['a','b','c'],columns = ['one','two','three','four'])
print(df)
df['five'] = [11,22,33]  #元素個數必須與行數相同,否則會報錯
print(df)
df.loc['d'] = [100,200,300,400,500]  #元素個數必須與列數相同,否則會報錯
print(df)
#   one  two  three  four
# a    0    1      2     3
# b    4    5      6     7
# c    8    9     10    11
#    one  two  three  four  five
# a    0    1      2     3    11
# b    4    5      6     7    22
# c    8    9     10    11    33
#    one  two  three  four  five
# a    0    1      2     3    11
# b    4    5      6     7    22
# c    8    9     10    11    33
# d  100  200    300   400   500
DataFrame增加行或列

?

③刪除

del df['列索引'] 直接刪除原DataFrame的列

df.drop('索引',axis = 0,inplace = False),drop可以刪除行也可以刪除列,默認axis為0即默認刪除行,為1則表示刪除列,如果給定的索引在行中或者列中不存在會報錯;

drop默認生成新的DataFrame不改變原DataFrame,即inplace=False,如果inplace設置為True則不生成新的DataFrame,而是直接修改原DataFrame。

arr = np.arange(12).reshape(3,4)
df = pd.DataFrame(arr,index = ['a','b','c'],columns = ['one','two','three','four'])
print(df)
del df['four']
print(df)  #del刪除原DataFrame的列
f = df.drop('c')
print(f)
print(df)
f = df.drop('three',axis=1,inplace=True)
print(f)
print(df)
#    one  two  three  four
# a    0    1      2     3
# b    4    5      6     7
# c    8    9     10    11
#    one  two  three
# a    0    1      2
# b    4    5      6
# c    8    9     10
#    one  two  three
# a    0    1      2
# b    4    5      6
#    one  two  three
# a    0    1      2
# b    4    5      6
# c    8    9     10
# None
#    one  two
# a    0    1
# b    4    5
# c    8    9
DataFrame刪除行或列

?

④相加

DataFrame與單個值相加或相減,對每個元素進行加或減即可。

DataFrame之間相加或相減,不要求index和columns相同,對行和列對應的部分加或減,多余的行和列都保留并且值全部為NaN。

arr1 = np.arange(12).reshape(3,4)
arr2 = np.arange(12).reshape(4,3)
df1 = pd.DataFrame(arr1,index = ['a','b','c'],columns = ['one','two','three','four'])
df2 = pd.DataFrame(arr2,index = ['a','b','c','d'],columns = ['one','two','three'])
print( df1 + 1 )
print( df1 + df2 )
#    one  two  three  four
# a    1    2      3     4
# b    5    6      7     8
# c    9   10     11    12
#    four   one  three   two
# a   NaN   0.0    4.0   2.0
# b   NaN   7.0   11.0   9.0
# c   NaN  14.0   18.0  16.0
# d   NaN   NaN    NaN   NaN
DataFrame相加或相減

?

⑤排序

按值排序:sort_values('列索引',ascending=True),即對某一列的值按行排序,默認升序排序,對多個列排序則用['列索引1','列索引2',...]

按index排序:sort_index(ascending=True),按照index的名稱進行排序,默認升序。

arr = np.random.randint(1,10,[4,3])
df = pd.DataFrame(arr,index = ['a','b','c','d'],columns = ['one','two','three'])
print(df)
print(df.sort_values(['one','three'],ascending=True))
print(df.sort_index(ascending=False))
#    one  two  three
# a    7    7      1
# b    5    7      1
# c    1    9      4
# d    7    9      9
#    one  two  three
# c    1    9      4
# b    5    7      1
# a    7    7      1
# d    7    9      9
#    one  two  three
# d    7    9      9
# c    1    9      4
# b    5    7      1
# a    7    7      1
DataFrame排序

??

?

轉載于:https://www.cnblogs.com/Forever77/p/11209186.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/392472.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/392472.shtml
英文地址,請注明出處:http://en.pswp.cn/news/392472.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

機器學習:分類_機器學習基礎:K最近鄰居分類

機器學習:分類In the previous stories, I had given an explanation of the program for implementation of various Regression models. Also, I had described the implementation of the Logistic Regression model. In this article, we shall see the algorithm of the K…

leetcode 714. 買賣股票的最佳時機含手續費(dp)

給定一個整數數組 prices&#xff0c;其中第 i 個元素代表了第 i 天的股票價格 &#xff1b;非負整數 fee 代表了交易股票的手續費用。 你可以無限次地完成交易&#xff0c;但是你每筆交易都需要付手續費。如果你已經購買了一個股票&#xff0c;在賣出它之前你就不能再繼續購買…

如何在Angular Material中制作自定義主題

by Charlee Li通過李李 如何在Angular Material中制作自定義主題 (How to make a custom theme in Angular Material) Angular Material is a great library that implements Material Design for Angular 2. The official document is sufficient regarding the component us…

最感嘆的莫過于一見如故,最悲傷的莫過于再見陌路。最深的孤獨,是你明知道自己的渴望,卻得對它裝聾作啞。最美的你不是生如夏花,而是在時間的長河里,波瀾不驚。...

最感嘆的莫過于一見如故&#xff0c;最悲傷的莫過于再見陌路。最深的孤獨&#xff0c;是你明知道自己的渴望&#xff0c;卻得對它裝聾作啞。最美的你不是生如夏花&#xff0c;而是在時間的長河里&#xff0c;波瀾不驚。轉載于:https://www.cnblogs.com/dj258/p/7003890.html

java vimrc_.vimrc技巧

-------------------------------------------------------------------" 設置字符編碼。參考&#xff1a;http://www.rainux.org/blog/index.php/2005/10/20/106" encoding: Vim 內部使用的字符編碼方式&#xff0c;包括 Vim 的buffer (緩沖區)、菜單文" 本、消…

將PDF和Gutenberg文檔格式轉換為文本:生產中的自然語言處理

Estimates state that 70%–85% of the world’s data is text (unstructured data). Most of the English and EU business data formats as byte text, MS Word, or Adobe PDF. [1]據估計&#xff0c;全球數據的70&#xff05;–85&#xff05;是文本(非結構化數據)。 大多數…

Go_筆試題記錄-指針與值類型實現接口的區別

1、如果Add函數的調用代碼為&#xff1a; func main() {var a Integer 1var b Integer 2var i interface{} &asum : i.(*Integer).Add(b)fmt.Println(sum) } 則Add函數定義正確的是&#xff08;&#xff09; A.type Integer int func (a Integer) Add(b Integer) Intege…

leetcode 48. 旋轉圖像

解題思路 將數組從里到外分為若干層&#xff0c; 數組 [1,2,3], [4,5,6][7,8,9]的最外層即為 [1,2,3] [4 6][7,8,9] &#xff0c;將一層分為4條邊&#xff0c;如741 123&#xff0c;將741放到123的位置&#xff0c;123放到369的位置&#xff0c;如此類推&#xff08;但是放置的…

如何恢復誤刪的OneNote頁面

今天不小心把半個月的日記刪掉了&#xff01;&#xff08;為了減少頁面數量&#xff0c;每個月的日記會放在同一個頁面上&#xff09;。 幸運的是OneNote有自動備份功能&#xff0c;喜極而泣。 操作方法來自微軟支持 打開丟失了最近筆記的筆記本。 單擊“文件”>“信息”&g…

javascript函數式_JavaScript中的函數式編程原理

javascript函數式After a long time learning and working with object-oriented programming, I took a step back to think about system complexity.經過長時間的學習和使用面向對象的編程&#xff0c;我退后了一步來思考系統的復雜性。 “Complexity is anything that mak…

java writeint_Java DataOutputStream.writeInt(int v)類型

DataOutputStream.writeInt(int v)方法示例DataOutputStream的DataOutputStream.writeInt(int v)方法具有以下語法。public final void writeInt(int v) throws IOException示例在下面的代碼中展示了如何使用DataOutputStream.writeInt(int v)方法。import java.io.DataInputSt…

協方差意味著什么_“零”到底意味著什么?

協方差意味著什么When I was an undergraduate student studying Data Science, one of my professors always asked the same question for every data set we worked with — “What does zero mean?”當我是一名研究數據科學的本科生時&#xff0c;我的一位教授總是對我們處…

Go_筆試題記錄-不熟悉的

1、golang中沒有隱藏的this指針&#xff0c;這句話的含義是&#xff08;&#xff09; A. 方法施加的對象顯式傳遞&#xff0c;沒有被隱藏起來 B. golang沿襲了傳統面向對象編程中的諸多概念&#xff0c;比如繼承、虛函數和構造函數 C. golang的面向對象表達更直觀&#xff0c;對…

leetcode 316. 去除重復字母(單調棧)

給你一個字符串 s &#xff0c;請你去除字符串中重復的字母&#xff0c;使得每個字母只出現一次。需保證 返回結果的字典序最小&#xff08;要求不能打亂其他字符的相對位置&#xff09;。 注意&#xff1a;該題與 1081 https://leetcode-cn.com/problems/smallest-subsequenc…

Go-json解碼到結構體

廢話不多說&#xff0c;直接干就得了&#xff0c;上代碼 package mainimport ("encoding/json""fmt" )type IT struct {Company string json:"company" Subjects []string json:"subjects"IsOk bool json:"isok"…

leetcode 746. 使用最小花費爬樓梯(dp)

數組的每個索引作為一個階梯&#xff0c;第 i個階梯對應著一個非負數的體力花費值 costi。 每當你爬上一個階梯你都要花費對應的體力花費值&#xff0c;然后你可以選擇繼續爬一個階梯或者爬兩個階梯。 您需要找到達到樓層頂部的最低花費。在開始時&#xff0c;你可以選擇從索…

安卓中經常使用控件遇到問題解決方法(持續更新和發現篇幅)(在textview上加一條線、待續)...

TextView設置最多顯示30個字符。超過部分顯示...(省略號)&#xff0c;有人說分別設置TextView的android:signature"true",而且設置android:ellipsize"end";可是我試了。居然成功了&#xff0c;供大家參考 [java] view plaincopy<TextView android:id…

網絡工程師晉升_晉升為工程師的最快方法

網絡工程師晉升by Sihui Huang黃思慧 晉升為工程師的最快方法 (The Fastest Way to Get Promoted as an Engineer) We all want to live up to our potential, grow in our career, and do the best work of our lives. Getting promoted at work not only proves that we hav…

java 銀行存取款_用Java編寫銀行存錢取錢

const readline require(‘readline-sync‘)//引用readline-synclet s 2;//錯誤的次數for (let i 0; i < 3; i) {console.log(‘請輸入名&#xff1a;(由英文組成)‘);let user readline.question();console.log(‘請輸入密碼&#xff1a;(由數字組成)‘);let password …

垃圾郵件分類 python_在python中創建SMS垃圾郵件分類器

垃圾郵件分類 python介紹 (Introduction) I have always been fascinated with Google’s gmail spam detection system, where it is able to seemingly effortlessly judge whether incoming emails are spam and therefore not worthy of our limited attention.我一直對Goo…