The 365 Data Science team is proud to invite you to our own community forum. A very well built system to support your queries, questions and give the chance to show your knowledge and help others in their path of becoming Data Science specialists.
Anybody can ask a question
Anybody can answer
The best answers are voted up and moderated by our team

white noise

white noise


wn = np.random.normal(loc = df.market_value.mean(), scale = df.market_value.std(), size = len(df))


while Running this code i was getting this error

Note: My code editor is Google colab

TypeError                                 Traceback (most recent call last)
<ipython-input-70-e07c336ccb3d> in <module>()
----> 1 wn = np.random.normal(loc = df.market_value.mean(), scale = df.market_value.std(), size = len(df))

5 frames

/usr/local/lib/python3.6/dist-packages/numpy/core/ in _sum(a, axis, dtype, out, keepdims, initial, where)
     36 def _sum(a, axis=None, dtype=None, out=None, keepdims=False,
     37          initial=_NoValue, where=True):
---> 38     return umr_sum(a, axis, dtype, out, keepdims, initial, where)
     40 def _prod(a, axis=None, dtype=None, out=None, keepdims=False,

TypeError: unsupported operand type(s) for +: 'float' and 'str'
2 Answers

365 Team

Hey Ramanjaneyulu,

Thanks for reaching out!

I’ve never had this specific error happen to me before. Would you mind letting me know what versions of pandas and NumPy you’re using here? Without that, I can give only 1 suggestion – try putting all the values apart from size into ‘float()’, like so:

wn = np.random.normal(loc = float(df.market_value.mean()), scale = float(df.market_value.std()), size = len(df))

365 Vik

i was used you “suggested Line” …………….its showing similar error, INSTALLED VERSIONS
commit : None
python :
python-bits : 64
OS : Linux
OS-release : 4.19.104+
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8

pandas : 1.0.3
numpy : 1.18.2
pytz : 2018.9
dateutil : 2.8.1
pip : 19.3.1
setuptools : 46.1.3
Cython : 0.29.16
pytest : 3.6.4
hypothesis : None
sphinx : 1.8.5
blosc : None
feather : 0.4.0
xlsxwriter : None
lxml.etree : 4.2.6
html5lib : 1.0.1
pymysql : None
psycopg2 : (dt dec pq3 ext lo64)
jinja2 : 2.11.1
IPython : 5.5.0
pandas_datareader: 0.8.1
bs4 : 4.6.3
bottleneck : 1.3.2
fastparquet : None
gcsfs : None
lxml.etree : 4.2.6
matplotlib : 3.2.1
numexpr : 2.7.1
odfpy : None
openpyxl : 2.5.9
pandas_gbq : 0.11.0
pyarrow : 0.14.1
pytables : None
pytest : 3.6.4
pyxlsb : None
s3fs : 0.4.2
scipy : 1.4.1
sqlalchemy : 1.3.15
tables : 3.4.4
tabulate : 0.8.7
xarray : 0.15.1
xlrd : 1.1.0
xlwt : 1.3.0
xlsxwriter : None
numba : 0.47.0

6 months

above pandas versions are i’m using

6 months

Hey Ram, so you’re using the latest versions of both packages (as am I) and the code runs smoothly for me. Hmmm, would you mind showing me a snippet of your code prior to calling this line of code?

6 months

# Code to read csv file into colaboratory:
!pip install -U -q PyDrive
from pydrive.auth import GoogleAuth
from import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials
#for authenticate
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import pandas.util.testing as tm

raw_csv_data = pd.read_csv(“/content/drive/My Drive/Datasets/Index2018.csv”)

df_comp = raw_csv_data.copy()







df_comp.spx.plot(title = ‘s&p500prices’, figsize = (20,5))

df_comp.dax.plot(title = “dax”, figsize = [20,5])

df_comp.spx.plot(title = “S&P 500 price”, figsize = [20,5])
df_comp.dax.plot(title = “dax price”, figsize = [20,5])
plt.title(“S&p vs Dax”)

import scipy.stats
import pylab

scipy.stats.probplot(df_comp.spx, plot=pylab)


pd.to_datetime( = pd.to_datetime(


df_comp.set_index(“date”, inplace=True)


df_comp = df_comp.asfreq(‘b’)



df_comp.spx = df_comp.spx.fillna(“ffill”)


df_comp.dax = df_comp.dax.fillna(“ffill”)

df_comp.ftse = df_comp.ftse.fillna(“ffill”)

df_comp.nikkei = df_comp.nikkei.fillna(“ffill”)



df_comp[“market_value”] = df_comp.spx


del df_comp[“dax”]

del df_comp[“ftse”]

del df_comp[“nikkei”]

del df_comp[“spx”]


size =int(len(df_comp)*0.8)

df = df_comp.iloc[:size]

df_test = df_comp.iloc[size:]



wn = np.random.normal(loc=df.market_value.mean(), scale=df.market_value.std(), size = len(df))

6 months

snippet is provided above google drive link…that is my error. as well as above code is i’m running

6 months

Hey Ram, I saw your code, but I’m not too familiar with Google Colab, so it’s taking me a while to figure out what’s wrong. Reading through your code I can’t immediately locate the issue, but it definitely looks like a package-environment incompatibility to me. Hope to provide an update soon.

6 months

Hey Ram, you’re filling missing values wrong. With df_comp.nikkei = df_comp.nikkei.fillna(“ffill”), you’re literally filling every missing value with the text “ffill”. You need to put “method = ” before it like we have shown in the video df_comp.nikkei = df_comp.nikkei.fillna(method =“ffill”). That’s why some of your values are text and it tells you that floats and strings are incompatible. Make sure to change this for all the different columns. Best, 365 Vik.

6 months

Hi Vik, i changed missing values as per you suggestion..still i'm facing error….there so no change

6 months

Hey Ram, since I need to post several snippets, I’ll be responding in a different “Answer” to this question.

6 months

i tried all formats and editors(spyder, jupiter, google colab) every browser showing same error…if you solve this problem….i will start my further lessons…i am waiting for this solution since three days.. as well as PLEASE provide RANDOM WALK CSV FILE. i already downloaded index2018.csv. file. after using it…i was braked at white noise problem…..thanks advance

6 months

Hey Ram, I literally posted a long answer to your question accompanied with snippets in this thread 10 minutes ago.

6 months

Also, the random walk csv file is attached to the lecture about Random Walks. It’s right there under the video (before the quiz).

6 months

365 Team

Hello again, Ram!

1.) It is crucial that you reload the data. If you’ve already filled it with text, you won’t find any new missing elements to fill properly. (Easiest thing to do is just rerun the entire code – top to bottom.)

2.) You need to fill the missing values in SPX before assigning its values to market_value. Otherwise, you’re not changing the variable you’re using to create the random walk.

3.) You need to change method = “ffill” in 4 separate places.

4.) If you’ve done this correctly, when you describe the dataframe your table should look like so:

If you’ve done it the way you did earlier, you’re going to have “ffill” as the top value.

5.) If you’ve made the changes appropriately, the code will run smoothly and you’ll get an output for the white noise variable.

For good measure, here is a link to my Google Colabs file, so you can cross-reference your code (I mostly just copied the code you sent me earlier).

365 Vik

Ready to Learn Data Science?
50% OFF