Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pandas column to numpy array

>>> import pandas as pd
>>> df = pd.DataFrame({"A":[1, 2], "B":[3, 4], "C":[5, 6]})
>>> df 
    A  B  C
 0  1  3  5
 1  2  4  6
>>> s_array = df[["A", "B", "C"]].to_numpy()
>>> s_array

array([[1, 3, 5],
   [2, 4, 6]]) 

>>> t_array = df[["B", "C"]].to_numpy() 
>>> print (t_array)

[[3 5]
 [4 6]]
Comment

column type pandas as numpy array

df['col1'] = df['col1'].apply(lambda x: np.array(x))

type(df['col1'].iloc[0])
numpy.ndarray
Comment

PREVIOUS NEXT
Code Example
Python :: print decimal formatting in python 
Python :: how to rearrange list in python 
Python :: how to reverse a number in python 
Python :: scrape with beautiful soup 
Python :: how to cycle through panes in tmux 
Python :: show image with ratio opencv python 
Python :: access dataframe column with space 
Python :: drop null rows pandas 
Python :: dataframe unique values in each column 
Python :: dont filter= true in scrapy 
Python :: how to factorise expressions in python 
Python :: How to count occurences of a certain item in a numpy array 
Python :: how to get the index of a value in pandas dataframe 
Python :: make selenium headless python 
Python :: regex all words longer than n 
Python :: python sum of digits in a string 
Python :: convert time zone pandas 
Python :: python imread multiple images 
Python :: text to dictionary python 
Python :: howt to make caluclator in python 
Python :: how to open a website with selenium python 
Python :: pip proxy settings 
Python :: python how to remove last letter from string 
Python :: plot pandas figsize 
Python :: remove warnings from jupter notebook 
Python :: sort list of string datetimes python 
Python :: Addition/subtraction of integers and integer-arrays with DatetimeArray is no longer supported 
Python :: cv2 add circle to image 
Python :: python comprehension with sum 
Python :: pygame left click 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =