Skip to content

Instantly share code, notes, and snippets.

View justimchung's full-sized avatar

鍾毓驥 justimchung

View GitHub Profile
@justimchung
justimchung / loadgapminder.py
Created August 26, 2019 07:40
Load data from gapminder.csv using Pandas
# 載入資料集
gapdf = pd.read_csv('gapminder.csv')
#秀出前 18 筆資料
gapdf.head(18)
country continent year lifeExp pop gdpPercap
Afghanistan Asia 1952 28.801 8425333 779.4453145
Afghanistan Asia 1957 30.332 9240934 820.8530296
Afghanistan Asia 1962 31.997 10267083 853.10071
Afghanistan Asia 1967 34.02 11537966 836.1971382
Afghanistan Asia 1972 36.088 13079460 739.9811058
Afghanistan Asia 1977 38.438 14880372 786.11336
Afghanistan Asia 1982 39.854 12881816 978.0114388
Afghanistan Asia 1987 40.822 13867957 852.3959448
Afghanistan Asia 1992 41.674 16317921 649.3413952
@justimchung
justimchung / Pandas_data_selection.ipynb
Last active June 30, 2018 13:51
說明如何由 Pandas 的 DataFrame 中取出資料
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Name height weight sex bdate city major
s1234567 Peter 175 70.45 1 1980/4/30 Tainan CSIE
e1234567 Mary 163 55 2 1981/12/21 Taipei EE
f1357689 John 180.4 80.3 1 1980/5/30 Tainan Stat
e1374659 Keven 182.5 77.6 1 1980/11/19 Taipei EE
s7758347 JoJo 170.3 50.3 2 1980/1/27 Taipei CSIE
s1334987 Emily 168.5 53.6 2 1982/10/13 Kaohsiung CSIE
e1384726 Ubuntu 177 68.3 1 1981/7/6 Kaohsiung EE
country capital area population
BR Brazil Brasilia 8.516 200.4
RU Russia Moscow 17.10 143.5
IN India New Delhi 3.286 1252
CH China Beijing 9.597 1357
SA South Africa Pretoria 1.221 52.98
import pandas as pd
years = [2014, 2015, 2016, 2017, 2018]
p = [1.8, 3.8, 4, 4.5, 2]
sp = pd.Series(p, index = years)
print(sp)
import pandas as pd
#建構一個 dictionary
dict = {
"country":["Brazil", "Russia", "India", "China", "South Africa"],
"capital":["Brasilia", "Moscow", "New Delhi", "Beijing", "Pretoria"],
"area":[8.516, 17.10, 3.286, 9.597, 1.221],
"population":[200.4, 143.5, 1252, 1357, 52.98] }
brics = pd.DataFrame(dict)
brics
int LIS(vector<int>& LISTbl)
{
if (LISTbl.size() == 0) return 0;
vector<int> LISLen(LISTbl.size(), 1);
for (int i = 1; i < LISTbl.size(); i++)
{
for (int j = 0; j < i; j++)
{
if (LISTbl[j] < LISTbl[i])
LISLen[i] = max(LISLen[i], LISLen[j] + 1);
void getMaxElementAndPos(vector<int>& LISTbl,
vector<int>& LISLen, int tNum, int tlen,
int tStart,
int & num, int & pos)
{
int max = numeric_limits<int>::min();
int maxPos;
for (int i = tStart; i >= 0; i--)
{
if (LISLen[i] == tlen && LISTbl[i] < tNum)
int LIS(vector<int>& LISTbl)
{
if (LISTbl.size() == 0) return 0;
vector<int> LISLen(LISTbl.size(), 1);
for (int i = 1; i < LISTbl.size(); i++)
{
for (int j = 0; j < i; j++)
{
if (LISTbl[j] < LISTbl[i])
LISLen[i] = max(LISLen[i], LISLen[j] + 1);