Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

有一个df,想增加一列df['new']=df.index值*2
请问如何写代码,谢谢。


用map和list也可以

import pandas as pd
df=pd.DataFrame(["a","b","c"],columns=["F"])
def foo(income):
   return("income"+str(income))

df["page"]=list(map(foo,df.index))
print(df)

image.png


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.5k views
Welcome To Ask or Share your Answers For Others

1 Answer

你不是已经写出来了吗 - -
df['new']=df.index * 2


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...