Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to convert a list into a dataframe in python

from pandas import DataFrame

People_List = ['Jon','Mark','Maria','Jill','Jack']

df = DataFrame (People_List,columns=['First_Name'])
print (df)
Comment

Basic method of Converting List to Dataframe

# import pandas as pd 

import pandas as pd 
# list of strings 
list = ['Softhunt.net', 'Learn', 'coding', 'skills']
# Calling DataFrame constructor on list 
df = pd.DataFrame(list) 
print(df)
Comment

pandas list to df

# import pandas as pd 
import pandas as pd 
  
# list of strings 
lst = ['Geeks', 'For', 'Geeks', 'is',  
            'portal', 'for', 'Geeks'] 
  
# Calling DataFrame constructor on list 
df = pd.DataFrame(lst) 
df 
Comment

List to Dataframe

# import pandas as pd 

import pandas as pd 
# list of strings 
lst = ['fav', 'tutor', 'coding', 'skills']
# Calling DataFrame constructor on list 
df = pd.DataFrame(lst) 
print(df) 
Comment

how to convert a list to dataframe in python

import pandas as pd
from pandas import DataFrame
df = DataFrame(lst,columns=['num'])
Comment

convert list to dataframe

L = ['Thanks You', 'Its fine no problem', 'Are you sure']

#create new df 
df = pd.DataFrame({'col':L})
print (df)

                   col
0           Thanks You
1  Its fine no problem
2         Are you sure
Comment

dataframe to list of lists

>>> df = pd.DataFrame([[1,2,3],[3,4,5]])
>>> lol = df.values.tolist()
>>> lol
[[1L, 2L, 3L], [3L, 4L, 5L]]
Comment

change dataframe to list

df.values.tolist()
Comment

list of dataframe to dataframe

import pandas as pd
df = pd.concat(list_of_dataframes)
# easy way
Comment

convert list of lists to pandas dataframe

salary = [['Company', 'Job', 'Salary($)'],
          ['Google', 'Machine Learning Engineer', 121000],
          ['Google', 'Data Scientist', 109000],
          ['Google', 'Tech Lead', 129000],
          ['Facebook', 'Data Scientist', 103000]]
df = pd.DataFrame(salary[1:], columns=salary[0])
Comment

PREVIOUS NEXT
Code Example
Python :: operator precedence in python 
Python :: calculate the same value in list i python 
Python :: custom keyboard telegram bot python 
Python :: python write line break 
Python :: check dir exist python 
Python :: binary to decimal python 
Python :: delete migrations django and start over deployment heroku 
Python :: valor absoluto en python 
Python :: how to sort a list of dictionary by value in descending order? 
Python :: django setup in windows 
Python :: std python 
Python :: mongo db python 
Python :: how to move tkinter images 
Python :: python version check in cmd 
Python :: string formatting in python 
Python :: library for converting text into image in python 
Python :: how to write a while statement in python 
Python :: dataframe to text file 
Python :: python code to print prime numbers 
Python :: generate unique id from given string python 
Python :: cv2 imshow in colab 
Python :: how to display csv in pandas 
Python :: python beautiful 
Python :: delete virtual environment in python windows 
Python :: python all lowercase letters 
Python :: difference between two dictionaries python 
Python :: string to dictionary python 
Python :: use loc for change values pandas 
Python :: vscode pylint missing module docstring 
Python :: tabula python 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =