how to convert pandas dataframe into a numpy array with floats

  floating-point, numpy, pandas, python

I cannot convert it using the following commands

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

df = pd.read_csv('sample.csv')

print(df.head())

np_array = df.to_numpy()

np_array.to_csv('sample.csv')

because the data frame contains floats. The head of df with col_names and row_names being integers 1-10 and 1-4, respectively; however, the values in df have decimals in the 1,000,000 place.
The error message i get is "IndexError: only integers, slices (:), ellipsis (...), numpy.newaxis (None) and integer or boolean arrays are valid indices
(project) [[email protected] dumpfolder]$ python3 awvetest_hmmm.py’

Source: Python Questions

LEAVE A COMMENT