Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to get a dataframe column as a list

import pandas as pd

data_dict = {'one': pd.Series([1, 2, 3], index=['a', 'b', 'c']),
             'two': pd.Series([1, 2, 3, 4], index=['a', 'b', 'c', 'd'])}

df = pd.DataFrame(data_dict)

print(f"DataFrame:
{df}
")
print(f"column types:
{df.dtypes}")

col_one_list = df['one'].tolist()

col_one_arr = df['one'].to_numpy()

print(f"
col_one_list:
{col_one_list}
type:{type(col_one_list)}")
print(f"
col_one_arr:
{col_one_arr}
type:{type(col_one_arr)}")
Comment

get dataframe column into a list

df_gearME = pd.read_excel('Gear M&Es.xlsx')
df_gearME['ColA'].to_list()
Comment

pandas read columns as list

from ast import literal_eval


df.Col3 = df.Col3.apply(literal_eval)
print(df.Col3[0][0])
Proj1
Comment

PREVIOUS NEXT
Code Example
Python :: django messages 
Python :: python datetime 
Python :: string format zero padded int python 
Python :: relativefrequencies of the unique values pandas 
Python :: dir() in python 
Python :: pandas convert first row to header 
Python :: python execute function from string 
Python :: Sending POST request in Django 
Python :: drop colums whoose value are object type in python 
Python :: python array methods 
Python :: python keyboard key codes 
Python :: if number is divisible by 3 python 
Python :: how to get the type of numpy array 
Python :: how to change port in flask app 
Python :: cardano 
Python :: Python string to var 
Python :: bytearray to hex python 
Python :: how to give a role permissions discord py 
Python :: python 1 line for loop with else 
Python :: python thread with return values? 
Python :: how to get input from pyqt line edit 
Python :: python program to check if binary representation is a palindrome 
Python :: django superuser 
Python :: import class in python 
Python :: how to change data type from int to float in dataframe 
Python :: python imaplib send email 
Python :: import all csv python 
Python :: how to call a random function in python 
Python :: python how to find circumference of a circle 
Python :: get dictionary values python 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =