Jump to content

Python pandas: Name Error

Featured Replies

Hi,

I am trying to execute the following code:


 

df2 = pd.DataFrame(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]), columns=['a', 'b', 'c'])
df2 = pd.DataFrame(data=d, dtype=np.int8)

print(df2)

I am getting the following error message:

Quote

df2 = pd.DataFrame(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]), columns=['a', 'b', 'c'])
NameError: name 'np' is not defined

Somebody please guide me.

 

Zulfi.

 

24 minutes ago, zak100 said:

NameError: name 'np' is not defined


What happens of you import numpy?

Quote

import numpy as np

 

  • Author

Hi,

Your solution worked.

Thanks a lot for your help.

God blesses you.

 

Zulfi.

 

Archived

This topic is now archived and is closed to further replies.

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.