assign

How to use square brackets as part of a variable name in pandas?

How to use square brackets as part of a variable name in pandas? Question: I am trying to use pandas.assign function. The function adds another column into an existing column. For example DataFrame1 = DataFrame1.assign(NewColName=[1,2,3,4]) Adds a new column named "NewColName". However, my ideal column name would be "Weight [kg]", and when I try to …

Total answers: 1

New to python. I need help assigning numerical values to an email list

New to python. I need help assigning numerical values to an email list Question: I am currently taking my first python class and I need help assigning numbers to an email when it is added to my list of emails. That way when someone wants to remove an email from the list, they can see …

Total answers: 1

Creating column based off values in separate row

Creating column based off values in separate row Question: Here is an example of my dataframe: df = pd.DataFrame([[‘Arsenal FC’, ”, ”], [‘In’, ‘Age’, ‘Nat.’], [‘Leandro Trossard’, 28, ‘Belgium’], [‘Jakub Kiwior’, 22, ‘Poland’], [‘Jorginho’, 32, ‘Italy’], [‘Chelsea FC’, ”, ”], [‘In’, ‘Age’, ‘Nat.’], [‘Enzo Fernández ‘, 22, ‘Argentina’], [‘Mykhaylo Mudryk’, 22, ‘Ukraine’], ], columns=[‘Player’, ‘Age’, …

Total answers: 2

How to permanently change a variable in Python?

How to permanently change a variable in Python? Question: I decided to make a code in Python that is like an ATM Machine, and Everything works very well, you can check your balance, extract or add money,and change the PIN code. But when I change the PIN code i tried to assign the "changed_pin_code" variable …

Total answers: 2

Pandas assign series to another Series based on index

Pandas assign series to another Series based on index Question: I have three Pandas Dataframes: df1: 0 NaN 1 NaN 2 NaN 3 NaN 4 NaN 5 NaN 6 NaN 7 NaN 8 NaN 9 NaN df2: 0 1 3 7 6 5 9 2 df3: 1 2 4 6 7 6 My goal is …

Total answers: 1

Combine and fill a Pandas Dataframe with the single row of another

Combine and fill a Pandas Dataframe with the single row of another Question: If I have two dataframes: df1: df1 = pd.DataFrame({‘A’:[10,20,15,30,45], ‘B’:[17,33,23,10,12]}) A B 0 10 17 1 20 33 2 15 23 3 30 10 4 45 12 df2: df2 = pd.DataFrame({‘C’:[‘cat’], ‘D’:[‘dog’], ‘E’:[’emu’], ‘F’:[‘frog’], ‘G’:[‘goat’], ‘H’:[‘horse’], ‘I’:[‘iguana’]}) C D E F G …

Total answers: 2

How to put a parameter in the assign function of DataFrames?

How to put a parameter in the assign function of DataFrames? Question: I would like to iterate over the columns and change the content of the columns with the assign function. Related to this problem So in that example they show that you can use the assign function: df = df.assign(industry=’yyy’) To change the content …

Total answers: 1

Assign new column in DataFrame based on if value is in a certain value range

Assign new column in DataFrame based on if value is in a certain value range Question: I have two DataFrames as follows: df_discount = pd.DataFrame(data={‘Graduation’ : np.arange(0,1000,100), ‘Discount %’ : np.arange(0,50,5)}) df_values = pd.DataFrame(data={‘Sum’ : [20,801,972,1061,1251]}) Now my goal is to get a new column df_values[‘New Sum’] for my df_values that applies the corresponding discount …

Total answers: 3

Pandas Method Chaining: getting KeyError on calculated column

Pandas Method Chaining: getting KeyError on calculated column Question: I’m scraping web data to get US college football poll top 25 information that I store in a Pandas dataframe. The data has multiple years of poll information, with preseason and final polls for each year. Each poll ranks teams from 1 to 25. Team ranks …

Total answers: 2