日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python数据结构练习

發布時間:2024/1/23 python 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python数据结构练习 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

貝葉斯估計用到的數據結構
Pandas常用到的:索引與切片,unique,value_counts(),reindex,sort_index(可以用于Seires,也可以是DataFrame,但只對index本身,index或columns本身進行排序,而不是其對應的元素進行排序),order(對Series中的值進行排序),sort_index(by=)對DataFrame中的列值進行排序!,相關系數corr,協方差cov
array與DataFrame

x=pd.Series([1,1,1,2,2,3]) print(x.unique()) print(x.value_counts())y_train=np.array([-1,-1,1,1,-1,-1,-1,1,1,1,1,1,1,1,-1]) print(y_train[0]) # error! print(y_train.unique()) Nunpy沒有unique()與value_counts()y=pd.DataFrame(y_train) print(y[0]) print(y[0].value_counts())frame=pd.DataFrame(np.arange(16).reshape((4,4)),index=['red','blue','black','green'],columns=['a','b','c','d']) #print(frame['a'] #選擇列 print(frame['a'].value_counts()) #選擇列中元素出現的次數 print(frame.a) #選擇列 print('----以上是列') print(frame.ix[2].value_counts()) #返回第3行內容,一行豎著顯示而已;同樣可以選擇行中元素出現的次數 print(frame.ix[[2,3]]) #返回第三行,第四行內容 print('----以上是行') print(frame['a']['red']) #引用二維表的某個元素,先是列標簽,再行標簽!**~~DataFrame引用元素先列后行~~ **[1 2 3] 1 3 2 2 3 1 dtype: int64 -1 0 -1 1 -1 2 1 3 1 4 -1 5 -1 6 -1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 -1 Name: 0, dtype: int321 9 -1 6 Name: 0, dtype: int64 12 1 4 1 8 1 0 1 Name: a, dtype: int64 red 0 blue 4 black 8 green 12 Name: a, dtype: int32 ----以上是列 11 1 10 1 9 1 8 1 Name: black, dtype: int64a b c d black 8 9 10 11 green 12 13 14 15 ----以上是行 0k近鄰算法用到的數據結構: Numpy中經常用到:shape,reshape,random,通用函數,聚合函數,索引與切片!

import numpy as np
import pandas as pd
x=np.array([1,2,3,4])
print(x.shape[0]) #4
#print(x.shape[1]) error
y=np.array([[1,2],[2,3],[3,4]])
print(y.shape[0]) #輸出個數3
print(y.shape[1]) #輸出維度2
print(y[:,1]) #切片,相當于輸出第二列
print(y[1])# 等價于y[1,]輸出第二行

輸出
4
3
2
[2 3 4]

Python自帶的數據結構

總結

以上是生活随笔為你收集整理的python数据结构练习的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。