DataFrame From Python
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
- flatxml tools for working with xml files as r dataframes
- data wrangling tidy data pandas
- program list python dataframe for practical file program list python
- interaction between sas and python for data handling and visualization
- append dataframe to text file python
- an introduction to python for text analysis ohio state university
- worksheet data handling using pandas
- practical file informatics practices class xii
- dataframe from python
- lab manual python programming lab 6cs4 23 jnit
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