#创建DataFrame
import pandas as pd
data_dict={
'currency':[
['PlN','USD'],
['EUR','USD','PLN','CAD'],
['GBP'],
['JPY','CZK','HUF'],[]
]
}
df=pd.DataFrame(data=data_dict)
df
#结果
currency | |
---|---|
0 | [PlN, USD] |
1 | [EUR, USD, PLN, CAD] |
2 | [GBP] |
3 | [JPY, CZK, HUF] |
4 | [] |
#len方法
df['number']=df['currency'].map(len)
df
#结果
currency | number | |
---|---|---|
0 | [PlN, USD] | 2 |
1 | [EUR, USD, PLN, CAD] | 4 |
2 | [GBP] | 1 |
3 | [JPY, CZK, HUF] | 3 |
4 | [] | 0 |