Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

convert numpy array to dataframe

import numpy as np
import pandas as pd

my_array = np.array([[11,22,33],[44,55,66]])

df = pd.DataFrame(my_array, columns = ['Column_A','Column_B','Column_C'])

print(df)
print(type(df))
Comment

convert a pandas df to a numpy array

x = df.to_numpy()
x
Comment

convert pandas dataframe to numpy dataframe

DataFrame.to_numpy(dtype=None, copy=False, na_value=<object object>)
Comment

panda dataframe to numpy matrix

# Imports
import numpy as np
import pandas as pd


df= pd.read_csv('/content/drive/MyDrive/Colab Notebooks/res_data/temp/file.txt', header = None, delim_whitespace=True, error_bad_lines=False).to_numpy()
df=df.astype(float)  # convert number to float for matric calculations

print(df.shape)  # .... (16, 1) initial shaope
df.resize(4, 4)

print(df)

[[ 1.  2.  3.  4.]
 [ 5.  6.  7.  8.]
 [ 9.  3.  5.  6.]
 [ 8.  9. 79.  0.]]
 
Comment

PREVIOUS NEXT
Code Example
Python :: flatten a list 
Python :: postgresql backup using python 
Python :: bitwise operators python 
Python :: python how to add to a list 
Python :: how to click a div element in selenium python 
Python :: python pass 
Python :: how to make an array in python 
Python :: wxpython icon 
Python :: input two numbers in python in a single line 
Python :: timeout socket python 
Python :: create a python api 
Python :: how to hide ticks in python 
Python :: python txt to parquet 
Python :: python prime number sum 
Python :: pytest - parameterizing tests 
Python :: convert datetime to date pandas 
Python :: remove file os python 
Python :: python 2d dictionary 
Python :: python processpoolexecutor 
Python :: finding random numbers python 
Python :: dataframe shift python 
Python :: tkinter maximise window 
Python :: python check variable size in memory 
Python :: python make 1d array from n-d array 
Python :: pandas not a time nat 
Python :: add values to tuple python 
Python :: get ticks pygame 
Python :: uninstall a python package from virtualenv 
Python :: group by month and day pandas 
Python :: stegano python 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =