I tried the following code and worked on it for a long time to correct it. But I do not know what I am doing wrong.
def hiLow(x):
if x > 10:
print(x, 'is greater than 10')
df['High/Low'] = 'High'
else:
print(x, 'is less than 10' )
df['High/Low'] = 'Low'
df['total'].map(hiLow)
I expected it will add 'High' in the second and third rows of the 'High/Low' column.
When I replaced df['High/Low'] = 'High' and df['High/Low'] = 'Low' with df['High/Low'] = x it prints 15 for all rows.
In the image,
- This output is correct
- Why is this all returned 'None'
- Why is this showing 'object' when at point 4 it is showing as 'int64'

df['High/Low'] = 'Low'replaces the entire columnHigh/Lowwith 'Low' (the same fordf['High/Low'] = 'High')and then the functions returnsNone(therefore it produces a Series of Nones as you see). You want to return a single value (return 'Low'), not mutating directly the column ofdfinside the function.