亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用用戶輸入在熊貓中創建列

如何使用用戶輸入在熊貓中創建列

小唯快跑啊 2023-03-08 15:58:51
我有一個數據表:sample_data = {'Sample': ['A', 'B', 'A', 'B'],                'Surface': ['Top', 'Bottom', 'Top', 'Bottom'],                'Intensity' : [21, 32, 14, 45]}sample_dataframe = pd.DataFrame(data=sample_data)我想添加用戶輸入以創建基于“示例”列的“條件”列。下面的函數返回錯誤“TypeError: 'DataFrame' object is not callable”def get_choice(df, column):    for i in column:        user_input = input('Condition= ')        df['Condition'] = df(user_input)    return dfget_choice(sample_dataframe, 'Sample')
查看完整描述

1 回答

?
森欄

TA貢獻1810條經驗 獲得超5個贊

我相信您在嘗試將與樣本中的元素對應的輸入添加到新列中。


import pandas as pd

sample_data = {'Sample': ['A', 'B', 'A', 'B'],

                'Surface': ['Top', 'Bottom', 'Top', 'Bottom'],

                'Intensity' : [21, 32, 14, 45]}

sample_dataframe = pd.DataFrame(data=sample_data)

def get_choice(df, column):

    user_input=[]

    for i in df[column]:

        print(i)

        user_input.append(input('Condition= '))

    df['Condition'] = user_input

    return df


print(get_choice(sample_dataframe, 'Sample'))


查看完整回答
反對 回復 2023-03-08
  • 1 回答
  • 0 關注
  • 92 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號