Python for Machine Learning

how to convert a pandas dataframe into a NumPy array.

I installed keras module in my system. But when I tried to import this module I got this below error : modulenotfounderror: no module named ‘keras’

How to create empty pandas dataframe?

I was following a tutorial about machine learning and following code works fine in tutorial but shows error when i try exact same thing:

from sklearn.cross_validation import train_test_split

It returns me this error:

ImportError: No module named sklearn.cross_validation

When running this code in TensorFlow,I got this error: module ‘tensorflow’ has no attribute ‘session’ .But it worked fine last time i ran it.

import tensorflow as tf

msg = tf.constant(‘Hello, TensorFlow!’)

sess = tf.Session()


I am not able to run this script.It shows this error “ImportError: numpy.core.multiarray failed to import” about numpy and i have already numpy installed.Here is my script:

import cv2
import time

cv.NamedWindow(“camera”, 1)

capture = cv.CaptureFromCAM(0)

while True:
img = cv.QueryFrame(capture)
cv.ShowImage(“camera”, img)
if cv.WaitKey(10) == 27:

columns = [‘Col1’, ‘Col2’, … , ‘ColN’]

df.drop(columns, inplace=True, axis=1)

import numpy as np

import pandas as pd

indexs = [1, 2, 3, 4, 5, 6, 7]

a = [np.nan, np.nan, np.nan, 0.1, 0.1, 0.1, 0.1]

b = [0.2, np.nan, 0.2, 0.2, 0.2, np.nan, np.nan]

c = [np.nan, 0.5, 0.5, np.nan, 0.5, 0.5, np.nan]

df = pd.DataFrame({‘A’: a, ‘B’: b, ‘C’: c}, index=index)

df = df.rename_axis(‘ID’).values


Have you installed keras properly.And if you have used anaconda to install ,sometimes we encounter such problems.Try pip to install keras after removing it first.

pip install keras

To create an empty dataframe in pandas, you this code:

import pandas as pd


The tutorial you are following must be old and not updated.This code would work fine with older version of scikit-learn but for new version,you have to use following code:

from sklearn.model_selection import train_test_split

You must have updated the Tensorflow to version 2 which now does not contain session().Tensorflow 2 runs Eager Execution by default, thus removing the need for Sessions but it can still be accessed via tf.compat.v1.Session().Here is how you can run your code in TF2:

import tensorflow as tf

msg = tf.constant(‘Hello, TensorFlow!’)


You need to upgrade your Numpy library. Your current version is not compatible with your CV2 module. You can use the below-given command to upgrade Numpy.

$ pip install -U numpy

i want data file pdf

Yes very nice and informative

How do i get “assignment on pandas” which was given in class

I have completed the exercise but progress is not showing there. What can I do?


Dear Learner,

Please drop a mail to mentioning the course name

Dear Learner,

Please drop a mail to mentioning the course name

Machine Learning with Python