PythonSTB commited on
Commit
ffb4905
·
verified ·
1 Parent(s): 2e42a4d

Delete pandas/PANDAS_USER_GUIDE.txt

Browse files
Files changed (1) hide show
  1. pandas/PANDAS_USER_GUIDE.txt +0 -142
pandas/PANDAS_USER_GUIDE.txt DELETED
@@ -1,142 +0,0 @@
1
- pandas — USER GUIDE (Android Python STB)
2
- =========================================
3
- Generated by RIMI
4
- Version: pandas 2.3.3
5
- Python: 3.12.14
6
-
7
- WHAT IS PANDAS?
8
- ---------------
9
- pandas is the most popular Python library for data analysis and manipulation.
10
- It provides fast, expressive DataFrames (tabular data) and Series (1D data)
11
- that make working with structured data easy and intuitive.
12
-
13
- In PythonSTB, pandas is used for:
14
- - EPG (Electronic Program Guide) data parsing and querying
15
- - Channel list management and filtering
16
- - Playlist data transformation
17
- - Analytics and statistics
18
- - CSV/JSON data processing
19
-
20
- QUICK START
21
- -----------
22
- import pandas as pd
23
-
24
- # Create a DataFrame
25
- df = pd.DataFrame({
26
- "channel": ["BBC One", "CNN", "Sky News"],
27
- "category": ["entertainment", "news", "news"],
28
- "rating": [4.5, 4.2, 4.0]
29
- })
30
-
31
- # Filter
32
- news = df[df["category"] == "news"]
33
-
34
- # Sort
35
- top = df.sort_values("rating", ascending=False)
36
-
37
- # Save / Load
38
- df.to_csv("channels.csv", index=False)
39
- df = pd.read_csv("channels.csv")
40
-
41
- CORE CONCEPTS
42
- -------------
43
- 1. DataFrame: 2D table (like a spreadsheet or SQL table)
44
- df = pd.DataFrame({"col1": [1,2,3], "col2": ["a","b","c"]})
45
-
46
- 2. Series: 1D column or row
47
- s = df["col1"]
48
-
49
- 3. Indexing:
50
- df.loc[row_label, col_label] # label-based
51
- df.iloc[row_int, col_int] # position-based
52
- df[df["col"] > value] # boolean mask
53
-
54
- 4. GroupBy:
55
- df.groupby("category")["rating"].mean()
56
-
57
- 5. Merge/Join:
58
- pd.merge(df1, df2, on="key")
59
-
60
- COMMON OPERATIONS
61
- -----------------
62
- # Filtering
63
- df[df["rating"] > 4.0]
64
- df.query("rating > 4.0")
65
- df.nlargest(5, "rating")
66
-
67
- # Aggregation
68
- df.groupby("category").agg({"rating": "mean", "channel": "count"})
69
-
70
- # Transform
71
- df["normalized"] = (df["rating"] - df["rating"].min()) / (df["rating"].max() - df["rating"].min())
72
-
73
- # Pivot
74
- pd.pivot_table(df, values="rating", index="category", aggfunc="mean")
75
-
76
- # Time series
77
- df["date"] = pd.to_datetime(df["date"])
78
- df.set_index("date").resample("D").mean()
79
-
80
- FILE I/O
81
- --------
82
- # CSV
83
- df.to_csv("data.csv", index=False)
84
- df = pd.read_csv("data.csv")
85
- df = pd.read_csv("data.csv", parse_dates=["date"])
86
-
87
- # JSON
88
- df.to_json("data.json", orient="records")
89
- df = pd.read_json("data.json", orient="records")
90
-
91
- # Excel (requires openpyxl)
92
- df.to_excel("data.xlsx", index=False)
93
- df = pd.read_excel("data.xlsx")
94
-
95
- EPG DATA EXAMPLE
96
- ----------------
97
- import pandas as pd
98
- from lxml import etree
99
-
100
- def parse_epg(xml_content):
101
- root = etree.fromstring(xml_content.encode())
102
- rows = []
103
- for prog in root.findall(".//programme"):
104
- rows.append({
105
- "channel": prog.get("channel"),
106
- "start": pd.to_datetime(prog.get("start"), format="%Y%m%d%H%M%S %z"),
107
- "stop": pd.to_datetime(prog.get("stop"), format="%Y%m%d%H%M%S %z"),
108
- "title": prog.findtext("title", ""),
109
- })
110
- return pd.DataFrame(rows)
111
-
112
- # Query: what's on now?
113
- now = pd.Timestamp.now(tz="UTC")
114
- on_now = epg[(epg["start"] <= now) & (epg["stop"] > now)]
115
-
116
- # Query: shows longer than 1 hour
117
- long_shows = epg[(epg["stop"] - epg["start"]) > pd.Timedelta(hours=1)]
118
-
119
- TIPS FOR ANDROID
120
- ----------------
121
- - pandas on Android is compiled with norelro + 16KB page alignment
122
- - Full wheel bundles numpy — no separate numpy install needed
123
- - Use zipfile-based installer (pip doesn't work from run-as)
124
- - pandas + numpy together use ~15MB installed
125
- - All DataFrame operations work the same as desktop Python
126
-
127
- TROUBLESHOOTING
128
- ---------------
129
- # ImportError: numpy required
130
- # Make sure pandas wheel with bundled numpy is installed (Full_Wheel)
131
-
132
- # Slow performance
133
- # Use vectorized operations instead of Python loops:
134
- # BAD: for i in range(len(df)): df.loc[i, "new"] = df.loc[i, "old"] * 2
135
- # GOOD: df["new"] = df["old"] * 2
136
-
137
- # Memory issues with large datasets
138
- # Use chunked reading:
139
- # for chunk in pd.read_csv("big.csv", chunksize=1000):
140
- # process(chunk)
141
-
142
- Generated by RIMI