Repository navigation
Python
g21589 edited this page Aug 20, 2024
·
18 revisions
import s3fs
import numpy as np
import pandas as pd
import polars as pl
import pyarrow.dataset as ds
from pyarrow import fs
storage_options = {
"key": "",
"secret": "",
"client_kwargs": {
"endpoint_url": "http://127.0.0.1:9000"
}
}
# fs = fs.S3FileSystem(endpoint_override=storage_options['client_kwargs']['endpoint_url'].replace("http://", "")),
# access_key=storage_options['key'],
# secret_key=storage_options['secret'])
fs = s3fs.S3FileSystem(endpoint_url=storage_options['client_kwargs']['endpoint_url'],
key=storage_options['key'],
secret=storage_options['secret'])
source = "s3://data/tripdata/*.parquet"
dset = ds.dataset("s3://data/tripdata/yellow_tripdata_2024-01.parquet", format="parquet", filesystem=fs)
df = (
pl.scan_pyarrow_dataset(dset)
.collect()
)
df = pl.scan_parquet(source, storage_options=storage_options)https://medium.com/bigdatarepublic/advanced-pandas-optimize-speed-and-memory-a654b53be6c2
- https://kknews.cc/zh-tw/code/4vvverq.html
- multiprocessing vs. multithreading vs. asyncio https://stackoverflow.com/questions/27435284/multiprocessing-vs-multithreading-vs-asyncio-in-python-3-4
import asyncio, nest_asyncio
nest_asyncio.apply() # Fix asyncio bug in IPython (RuntimeError: This event loop is already running)
async def example1(): # 定義一個中間會被中斷的協程
print("Start example1 coroutin.")
await asyncio.sleep(1) # 中斷協程一秒
print("Finish example1 coroutin.")
async def example2(): # 定義一個協程
print("Start example2 coroutin.")
# do some process...
print("Finish example2 coroutin.")
tasks = [
asyncio.ensure_future(example1()),
asyncio.ensure_future(example2()),
]
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.wait(tasks))https://pypi.org/project/kaleido/#files
- https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md#usage-as-a-c_library
- https://source.chromium.org/chromium/chromium/src/+/master:headless/app/headless_example.cc
- ./repos/kaleido/cc/kaleido.cc:453
void OnHeadlessBrowserStarted(headless::HeadlessBrowser* browser)Time: 26.1649 sec Time: 31.2114 sec
Time: 3.2116 sec Time: 8.1961 sec
Time: 0.412 sec