Answers for "to array pandas"

0

convert a pandas df to a numpy array

x = df.to_numpy()
x
Posted by: Guest on August-02-2021
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

Python Answers by Framework

Browse Popular Code Answers by Language