-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparse_data.py
More file actions
68 lines (55 loc) · 1.7 KB
/
parse_data.py
File metadata and controls
68 lines (55 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import polars as pl
pl.Config.set_fmt_str_lengths(150)
# Namespaces
ns = "http://data.treehouse.example/"
ns_tpl = "http://data.treehouse.example/tpl/"
ns_sh = "http://data.treehouse.example/sh/"
# PLANETS AND SATELLITES: https://github.com/devstronomy/nasa-data-scraper/tree/master
# STARS: https://www.kaggle.com/datasets/waqi786/stars-dataset/data
def planets():
# Read planet CSV
df_planets = pl.read_csv("data/planets.csv")
# Create subject URI for planets
df_planets = df_planets.with_columns(
(ns + pl.col("planet")).alias("planet_uri")
)
# Chose columns to play with
df_planets = df_planets.select(
["planet",
"planet_uri", # the new column we just made :-)
"mean_temperature",
"length_of_day",
"orbital_period"
])
return df_planets
def satellites():
df_satellites = pl.read_csv("data/satellites.csv")
df_satellites = df_satellites.with_columns(
(ns + pl.col("planet")).alias("planet_uri")
)
df_satellites = df_satellites.with_columns(
(ns + pl.col("name")
.str.replace_all("/", "-"))
.str.replace_all(" ", "-")
.alias("satellite_uri")
)
df_satellites = df_satellites.select(
["name", "planet_uri", "satellite_uri", "albedo", "radius"]
)
df_satellites = (
df_satellites
.with_columns(
pl.col("albedo")
.cast(pl.Float64, strict=False)
.alias("albedo")
)
.with_columns(
pl.col("radius")
.cast(pl.Float64, strict=False)
.alias("radius")
)
)
return df_satellites
def stars():
df_stars = pl.read_csv("data/stars.csv")
return df_stars