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 :: How to wait a page is loaded in Python Selenium 
Python :: python get function name 
Python :: python counting dictionary 
Python :: open word from python 
Python :: pandas calculate same day 3 months ago dateoffset 
Python :: how to scrape multiple pages using selenium in python 
Python :: how to convert all items in a list to integer python 
Python :: set column datatype pandas 
Python :: python while loop 
Python :: python list fill nan 
Python :: import antigravity in python 
Python :: python plot groupby colors 
Python :: python sort array of dictionary by value 
Python :: remove character(s)from each column in dataframe 
Python :: django start project 
Python :: python mettre en minuscule 
Python :: make a gif with images python 
Python :: python read json file array 
Python :: Load dataset from seaborn 
Python :: types of dict comprehension 
Python :: fasttext python 
Python :: position in array python 
Python :: copy only some columns to new dataframe in r 
Python :: Determine the sum of al digits of n 
Python :: startapp django 
Python :: how to create a variable in python 
Python :: python to mac executable 
Python :: python series 
Python :: is python good for web development 
Python :: django queryset to form 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =