Raise ValueError("DataFrame constructor not properly called!") while converting Save Numpy Array to CSV File

Viewed 35

I have dataset MSL_test.npy file , how can I convert them into csv format, I already saw previous thread on this but unable to solve the error

I tried to execute this code

import pandas as pd

df = pd.DataFrame("Z:/ADwork2/python/PM/SMAP/SMAP_train.npy")
df.to_csv('Z:/ADwork2/python/PM/SMAP/SMAP.csv',index=False)

but got this error

File "C:\Users\user11\AppData\Roaming\Python\Python39\site-packages\pandas\core\frame.py", line 529, in init raise ValueError("DataFrame constructor not properly called!") ValueError: DataFrame constructor not properly called!

1 Answers

You have to load the numpy file first by using numpy.load. Try this :

import pandas as pd
import numpy as np

array = np.load(r'Z:/ADwork2/python/PM/SMAP/SMAP_train.npy')

df = pd.DataFrame(array)
df.to_csv(r'Z:/ADwork2/python/PM/SMAP/SMAP.csv',index=False)
Related