Cannot Concatenate 'Str' and 'Float' Objects

python,typeerror:cannot concatenate 'str 'and 'float' objects

You need to convert the calculated number into a string before performing string methods on it. This might help:

("Celcius is:" + str(celcius))

You could also use the following method if you do not want to convert float to string:

("Celcius is: {}".format(celcius))

TypeError: cannot concatenate 'str' and 'float' objects : pandas

def f(x):
control = x.loc[(x.test==0)]
control = control['conversion']
test = x.loc[(x.test==1)]
test = test['conversion']
p_value = stats.ttest_ind(control,test)[0]
control_mean = control.mean()
test_mean = test.mean()
return pd.Series({'p_value': p_value, 'conversion_test': test_mean, 'conversion_control': control_mean})

This did the trick!! Thank you again @ juanpa.arrivillaga!!

plt.bar - TypeError: cannot concatenate 'str' and 'float' objects

That is because bar needs x-coordinates, but your x_axis is an array of strings. So, bar does not know where to plot the bars. What you need is the following:

import numpy as np 
import matplotlib.pyplot as plt

y_axis = np.array([ 79, 14, 12, 9, 196, 27, 66, 12, 7, 32, 7, 18, 26,
45, 31, 95, 16, 51, 28, 105, 67])

x_labels = np.array(['administrator', 'retired', 'lawyer', 'none', 'student',
'technician', 'programmer', 'salesman', 'homemaker', 'executive',
'doctor', 'entertainment', 'marketing', 'writer', 'scientist',
'educator', 'healthcare', 'librarian', 'artist', 'other', 'engineer'],
dtype='|S13')

w = 3
nitems = len(y_axis)
x_axis = np.arange(0, nitems*w, w) # set up a array of x-coordinates

fig, ax = plt.subplots(1)
ax.bar(x_axis, y_axis, width=w, align='center')
ax.set_xticks(x_axis);
ax.set_xticklabels(x_labels, rotation=90);
plt.show()


Related Topics



Leave a reply



Submit