Pandas¶
Description:
- A Python package that provides fast, flexible, and expressive data structures designed to make working with "relational" or "labeled" data both easy and intuitive.
Resources:
Example 1¶
Create a dataframe
In [ ]:
Copied!
import pandas as pd
df = pd.DataFrame(
{
"Name": [
"Braund, Mr. Owen Harris",
"Allen, Mr. William Henry",
"Bonnell, Miss. Elizabeth",
],
"Age": [22, 35, 58],
"Sex": ["male", "male", "female"],
}
)
df
import pandas as pd
df = pd.DataFrame(
{
"Name": [
"Braund, Mr. Owen Harris",
"Allen, Mr. William Henry",
"Bonnell, Miss. Elizabeth",
],
"Age": [22, 35, 58],
"Sex": ["male", "male", "female"],
}
)
df
Example 2¶
Download a remote csv asynchronously and create a dataframe from it
In [ ]:
Copied!
import pandas as pd
from fsspec import filesystem
from pathlib import Path
import asyncio
tmp = "/tmp/demo_notebooks"
Path(tmp).mkdir(exist_ok=True)
url = "https://raw.githubusercontent.com/pandas-dev/pandas/main/doc/data/titanic.csv"
async def download_csv():
fs = filesystem("http", asynchronous=True)
session = await fs.set_session()
out = await fs._get(url, f"{tmp}/titanic.csv")
await session.close()
asyncio.run(download_csv())
titanic = pd.read_csv(f"{tmp}/titanic.csv")
titanic.head()
import pandas as pd
from fsspec import filesystem
from pathlib import Path
import asyncio
tmp = "/tmp/demo_notebooks"
Path(tmp).mkdir(exist_ok=True)
url = "https://raw.githubusercontent.com/pandas-dev/pandas/main/doc/data/titanic.csv"
async def download_csv():
fs = filesystem("http", asynchronous=True)
session = await fs.set_session()
out = await fs._get(url, f"{tmp}/titanic.csv")
await session.close()
asyncio.run(download_csv())
titanic = pd.read_csv(f"{tmp}/titanic.csv")
titanic.head()