![](/img/trans.png)
[英]Loop over data in column 1 from dataframe_1 & assign to rows of a different dataframe_2 in a new column, with col 2 on dataframe_1 showing the limit
[英]assign a new col to a dataframe
我有一個函數,它獲取一個數據框並根據表中的每個賣出計算一個值並返回一個列表。 我使用下面的代碼使用我的函數的輸出在我的表中分配一個新列:
df.assign(Points = pd.Series(calculate_point(df), index=df.index))
不幸的是它不起作用,我不知道會有什么問題。 你能幫我弄清楚嗎?
謝謝哈尼
做就是了:
df['Points'] = pd.Series(calculate_point(df), index=df.index)
讓我知道這個是否奏效。
我所做的是分配這樣的列:
df['newColumnName'] = pd.Series(calculate_point(df), index=df.index)
如果您想要效率,請使用其他:
df.loc[:,'newColumnName'] = pd.Series(calculate_point(df), index=df.index)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.