Pandas一些常見場景的解決方案

2021-09-27 09:45:17 字數 1554 閱讀 1293

場景如下:

import pandas as pd

data =

data = pd.dataframe(data)

data

onetwo

three

four

a1.0

1.01.0

5.0b

1.08.0

5.03.0

c3.0

2.06.0

3.0d

4.03.0

6.07.0

篩選出data中列』two』中的值在list[1., 3., 5., 7., 9.]中的資料

test_list =[1

.,3.

,5.,

7.,9

.]data1 = data[data[

'two'

].isin(test_list)

]data1

onetwo

three

four

a1.0

1.01.0

5.0d

4.03.0

6.07.0

篩選出data中列』two』中的值在list[1., 3., 5., 7., 9.]中的資料,並修改列』four』,值為』奇數』

data2 = data

data2.loc[data[

'two'

].isin(test_list)

,'four']=

'奇數'

data2

onetwo

three

four

a1.0

1.01.0奇數b

1.08.0

5.03

c3.0

2.06.03d

4.03.0

6.0奇數

data3 = data

defmy_test

(item)

: b =

for i in

range

(item.shape[0]

):a = item.iloc[i,:]

.astype(

str)

','.join(

list

(a.values)))

return b

data3 = data3.groupby(by=

'one').

(lambda x :

';'.join(my_test(x)))

.reset_index(

)data3

one0

01.0

1.0,1.0,1.0,奇數;1.0,8.0,5.0,3.0

13.0

3.0,2.0,6.0,3.0

24.0

4.0,3.0,6.0,奇數

持續更新中…

常見的一些git操作場景

git config global user.name administrator git config global user.email 2312119590 qq.com git clone cd secondproject touch readme.md git add readme.md ...

pandas的一些用法

讀取以 t為分隔符的不帶volume的資料names a b c d e f g df pd.read table filename sep t names names 刪除df中某一行df.drop labels none axis 0,index none columns none level ...

pandas的一些誤區

data frame pd.dataframe data in 13 frame.iloc 6 1,asf 201 這一行會報錯indexerror single positional indexer is out of bounds in 14 frame.loc 6 1,hh 612 正確新增一...