Answers for "dataframe to array in python"

5

dataframe from arrays python

import pandas as pd
df=pd.DataFrame({'col1':vect1,'col2':vect2})
Posted by: Guest on March-20-2020
7

dataframe object to numpy array

import pandas as pd

#initialize a dataframe
df = pd.DataFrame(
	[[21, 72, 67],
	[23, 78, 69],
	[32, 74, 56],
	[52, 54, 76]],
	columns=['a', 'b', 'c'])

#convert dataframe to numpy array
arr = df.to_numpy()

print('nNumpy Arrayn----------n', arr)
Posted by: Guest on August-22-2020
0

Convert Dataframe to an array

import numpy as np
import pandas as pd
  
  
arr = np.random.rand(4, 3)
print("Numpy array:")
print(arr)
  
# convert numpy array to dataframe
df = pd.DataFrame(arr, columns =['A', 'B', 'C'])
print("nPandas DataFrame: ")
df
Posted by: Guest on August-25-2021
0

list dataframe to numpy array

df.values

array([[nan, 0.2, nan],
       [nan, nan, 0.5],
       [nan, 0.2, 0.5],
       [0.1, 0.2, nan],
       [0.1, 0.2, 0.5],
       [0.1, nan, 0.5],
       [0.1, nan, nan]])
Posted by: Guest on September-06-2020

Code answers related to "dataframe to array in python"

Python Answers by Framework

Browse Popular Code Answers by Language