2.1 Importing Python Data
2.1 Importing Python Data
Importing Data
>>> df_sheet2 = data.parse(‘1960-1966’, pickled_data = pickle.load(file)
skiprows=[0],
names=[‘Country’,
‘AAM: War(2002)’])
>>> df_sheet1 = data.parse(0,
parse_cols=[0],
skiprows=[0], HDF5 Files
names=[‘Country’])
Learn Python for Data Science Interactively To access the sheet names, use the sheet_names attribute:
>>> import h5py
>>> filename = ‘H-H1_LOSC_4_v1-815411200-4096.hdf5’
>>> data = h5py.File(filename, ‘r’)
>>> data.sheet_names
Importing Data in Python
Most of the time, you’ll use either NumPy or pandas to import
your data:
Using the context manager with Accessing Data Items with Keys
Querying Relational Databases
>>> with open(‘huck_finn.txt’, ‘r’) as file:
>>> con = engine.connect() >>> for key in data [‘meta’].keys() Explore the HDF5 structure
print(file.readline()) Read a single line
>>> rs = con.execute(“SELECT * FROM Orders”) print(key)
print(file.readline())
>>> df = pd.DataFrame(rs.fetchall()) Description
print(file.readline())
>>> df.columns = rs.keys() DescriptionURL
>>> con.close() Detector
Duration
GPSstart
Using the context manager with Observatory
Table Data: Flat Files Type
>>> with engine.connect() as con:
UTCstart
rs = con.execute(“SELECT OrderID FROM Orders”)
Importing Flat Files with numpy >>> print(data[‘meta’][‘Description’].value) Retrieve the value for a key
df = pd.DataFrame(rs.fetchmany(size=5))
Files with one data type df.columns = rs.keys()