You are not logged in.
Pages: 1
1. Python Library
DataFrame object comes from Python Library: Pandas (Python Data Analysis Library).
2. Learning Material
Web Site:
https://medium.co1626.40m/%E8%B3%87%E6% … f54ff152bc
PDF version:
http://w.tkolp.com/data/addiesam/Python … data_1.pdf
3. Sample Data File
Okun’s law data (1948-I — 2002-I):
un - Federal Reserve Bank of St. Louis Economic Data: (http://research.stlouisfed.org/fred2/se … ta?&cid=12)
GNP - Federal Reserve Bank of St. Louis Economic Data: (http://research.stlouisfed.org/fred2/se … a?&cid=106)
Local file as at 2020-01-16:
http://w.tkolp.com/data/addiesam/Python … /okun.xlsx
http://w.tkolp.com/data/addiesam/Python … UNRATE.csv
http://w.tkolp.com/data/addiesam/Python … GNPC96.csv
4. Reference
1. https://pandas.pydata.org
2. Pandas documentation
3. Pandas documentation (.pdf file)
5. Coding
Example - Read Excel Data to DateFrame[ Object
Python Code:
import numpy as np
import pandas as pd
okun = pd.read_excel('okun.xlxs')
okun.head()
okun.tail(3)
Output:
gnp un
0 1626.4 3.733333
1 1655.5 3.666667
2 1665.1 3.766667
3 1669.0 3.833333
4 1643.8 4.666667gnp un
232 11342.7 4.733333
233 11408.5 4.633333
234 11458.5 4.700000
Remark:
1. We use the functions provided by DataFrame object, which comes from Pandas library, and it is not related to Excel anymore.
2. In this example, "okun" is the variable to store the DataFrame object which loaded the Excel data.
3. An object is an abstract data type with the addition of polymorphism and inheritance. Simply speaking, object is something with status and functions. e.g. TV is an object with status --- current channel and 2 functions --- display and play sound.
Example - Get Data from DataFrame
Python Code:
okun.iloc[0][0]
okun['gnp'][0]
okun.gnp[0]
Output:
1626.4
1626.4
1626.4
Remark:
"gnp" is the column name.
"iloc" is a function of DataFrame object.
Index starts from 0. "okun.iloc[0][0]" is the data in "A2" where "A1" is column name.
Example - Write Data to .csv File
Python Code:
okun.to_csv('test.csv', mode='w')
Output:
Pages: 1