1

I have a data table:

sample_data = {'Sample': ['A', 'B', 'A', 'B'],
                'Surface': ['Top', 'Bottom', 'Top', 'Bottom'],
                'Intensity' : [21, 32, 14, 45]}

sample_dataframe = pd.DataFrame(data=sample_data)

I would like to add user input to create a column 'Condition' based on the 'Sample' column. The function below returns the error "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 df

get_choice(sample_dataframe, 'Sample')
1
  • It seems weird to me that you pass a string column name and then proceed to iterate over the characters (??). Did you mean to pass ['Sample', ] instead of 'Sample'? Commented Jul 14, 2020 at 18:33

1 Answer 1

1

i believe you where trying to add inputs corresponding to elements in sample to a new column.

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'))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.