Python 資料處理(1)

2021-10-10 01:27:20 字數 851 閱讀 1390

記錄最近處理資料集常用的幾個操作。

刪除行之後行號就不是連續的了,索引行號的時候不方便。這裡重新設定行號,並把原先的行號drop掉。

df=df.reset_index(drop=

true

)

統計,排序。

df.colnames.value_counts(

).sort_index(

)

.loc 引用行列名稱。str.upper()。』-』.join()。

df.loc[i,

'key']=

'-'.join(

[a,b,c]

)df.loc[i,

'storm name'][

0:4]

.upper(

)

# extract month from landfall date

df['month'

]= df[

'landfall date'].

(lambda x:

str(x)[0

:3])

# 將月份從英文縮寫轉成數字

month2int=

df['monthint'

]=df[

'month'].

(lambda x: month2int[x]

)

# combine two tables

merge = pd.merge(df1, df2, on=

['key'])

merge

python 資料處理 1

python 基礎 各種資料型別的用途 1.字串 1 大小寫轉換 例 pharse he is very beautiful print pharse.upper other djfsdf print other.lower 以上 並沒有將變數永久改為大 小寫模式,若想永久改變 pharse he ...

Python資料處理 numpy 1

python中資料處理最基礎的乙個包 numpy。它能很好的進行資料準備,類似與r語言中的資料框 dataframe 一樣。今天,就來從最基礎的開始學習。import numpy as np data 0.95,0.25,0.89 0.56,0.24,0.91 data np.array data ...

Python 資料處理

將檔案切分,存入列表 strip split with open james.txt as jaf data jaf.readline james data.strip split 資料檔案為 2 34,3 21,2.34,2.45,3.01,2 01,2 01,3 10,2 22 print ja...