DataFrame From Python
[Pages:1]Creating Pandas DataFrames from Python Lists and Dictionaries
Dictionary
List
s al es = [ { ' ac c ount ' : ' J ones LLC' , ' J an' : 150, ' Feb' : 200, ' Mar ' : 140} , { ' ac c ount ' : ' Al pha Co' , ' J an' : 200, ' Feb' : 210, ' Mar ' : 215} , { ' ac c ount ' : ' Bl ue I nc ' , ' J an' : 50, ' Feb' : 90, ' Mar ' : 95 } ]
df = pd. Dat aFr ame( s al es )
s al es = [ ( ' J ones LLC' , 150, 200, 50) , ( ' Al pha Co' , 200, 210, 90) , ( ' Bl ue I nc ' , 140, 215, 95) ]
l abel s = [ ' ac c ount ' , ' J an' , ' Feb' , ' Mar ' ] df = pd. Dat aFr ame. f r om_r ec or ds ( s al es , c ol umns =l abel s )
Row Oriented
Column Oriented
def aul t
account
Jan
Feb
Mar
0
Jones LLC 150
200
140
1
Alpha Co
200
210
215
2
Blue Inc
50
90
95
f r om_r ec or ds
s al es = { ' ac c ount ' : [ ' J ones LLC' , ' Al pha Co' , ' Jan' : [ 150, 200, 50] , ' Feb' : [ 200, 210, 90] , ' Mar ' : [ 140, 215, 95] }
df = pd. Dat aFr ame. f r om_di c t ( s al es )
' Bl ue I nc ' ] ,
f r om_di c t
When using a dictionary, column order is not preserved. Explicitly order them:
df = df [ [ ' ac c ount ' , ' J an' , ' Feb' , ' Mar ' ] ]
s al es = [ ( ' ac c ount ' , [ ' J ones LLC' , ' Al pha Co' , ( ' Jan' , [ 150, 200, 50] ) , ( ' Feb' , [ 200, 210, 90] ) , ( ' Mar ' , [ 140, 215, 95] ) ]
df = pd. Dat aFr ame. f r om_i t ems ( s al es )
' Bl ue I nc ' ] ) ,
f r om_i t ems
Practical Business Python -
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- reportlab pdf generation user guide
- worksheet data handling using pandas
- combining latex with python tex users group tug
- pseudo code tutorial and exercises teacher s version
- data handling using pandas 1
- handling nested parallelism and extreme load imbalance in an arxiv
- dataframe from python
- data wrangling tidy data pandas
- introduction to computers programming loops in python
- chapter 6 lists and for loops washington state university
Related searches
- create dataframe from dataframe pandas
- python load dataframe from csv
- python pandas create dataframe from list
- pandas dataframe from another dataframe
- create pandas dataframe from columns
- creating a dataframe from lists
- create dataframe from text
- pandas dataframe from csv
- dataframe from array pandas
- pandas make dataframe from array
- create dataframe from rdd
- spark create dataframe from list