|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- def t_or_w(x,b_or_t):
- for a,b in zip(x,b_or_t):
- #print(a)
- #print(b)
- if '千' in str(a):
- #print(1)
- b=int(b)*1000
- #print(b)
- return b
- elif '万' in str(a):
- b=int(b)*10000
- #print(b)
- return b
- df.apply(t_or_w(df['salary'],df['bottom']),axis=1)
复制代码
怎么把df.apply(t_or_w(df['salary'],df['bottom']),axis=1)的结果更新到列表里,即想要实现df.bottom=df.apply(t_or_w(df['salary'],df['bottom']),axis=1)
不知道是不是你想要的代碼:
- import pandas as pd
- import numpy as np
- salary = [13, 5, 8, 11, 9]
- values = ["千", "萬", "千", "千", "萬"]
- df = pd.DataFrame([list(i) for i in zip(*[salary, values])], columns = ['A', 'B'])
- print(df, end = "\n\n")
- def funct(arr: list):
- a, b = arr
- if b == "千":
- return a*1000
- else:
- return a*10000
- data = df.apply(funct, axis=1)
- print(data)
复制代码- A B
- 0 13 千
- 1 5 萬
- 2 8 千
- 3 11 千
- 4 9 萬
- 0 13000
- 1 50000
- 2 8000
- 3 11000
- 4 90000
- dtype: int64
复制代码
|
|