日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

contains方法_【原创】Pandas数据处理系列(二):常用处理方法笔记

發布時間:2024/8/23 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 contains方法_【原创】Pandas数据处理系列(二):常用处理方法笔记 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Pandas的魅力在于處理數據的靈活性,但是由于太靈活,會導致使用者很容易忘記各類方法。在Pandas學習這件事情上,真正體現了好記性不如爛筆頭的方法特性。故特用此文章記錄Pandas常用的數據處理方法,需要用的時候,打開此文章直接查閱即可。

1.多列排序

enddf=newdf.sort_values(['date','Buypower'],ascending=[True,False])

2.數組差集

set(tradedate).difference(set(dailylist))

3.按列條件更新 (等同SQL: update xxx=zzz where yyy)

datadf.loc[(datadf.bigamount > 300 * 10000) & (datadf.bigamount <= 1000 * 10000), 'bigamount'] = 300 * 10000

4.列轉換成date類型

subdf2.date=pd.to_datetime(subdf2.date)

5.設置多級索引:

df.set_index(['ts_code','date'])

6.相鄰行操作:

df=df.apply(lambda x:x-x.shift(1))

7.lambda用if:

df=df.apply(lambda x:x/x.shift(1) if x.name[0] == x.shift(1).name[0] else x )

8.刪除空行:

weekdf=weekdf.dropna()

9.matplotlib畫柱狀圖:

subdf2.plot(kind='bar',title=code)

10.matplotlib畫水平線:

plt.axhline(y=8000, color='r', linestyle='-')

11.matplotlib柱狀圖上添加數量標簽文字:

for x, y in enumerate(subdf2['vol'].values):

print(x, y)

plt.text(x-0.5, y+50, "%s" %y)

12.列重命名:

enddf=enddf.rename(columns={'index':'ts_code'})

13.列截取字符串:

mergdf.list_date = mergdf.list_date.str[:4]

14.timedelta取出天數:

mergdf.list_date=mergdf.list_date.astype('timedelta64[D]').astype(int)

15.Series轉換成dataframe:

grpdf=grpdf.to_frame()

16.某列包含字符串,相當于SQL中的 like %xx%。

df0[df0.UpReason.str.contains('xxx')

17.刪除某列

df.drop('Type', axis='columns')

總結

以上是生活随笔為你收集整理的contains方法_【原创】Pandas数据处理系列(二):常用处理方法笔记的全部內容,希望文章能夠幫你解決所遇到的問題。

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