• Twitter
  • Facebook
  • Google+
  • Instagram
  • Youtube

About me

Let me introduce myself


A bit about me

Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident.

I have more than 5 years’ experience related to manufacturing of optical design ,Camera Module and also have some experience on coding . Having years of RD experience that cooperated with international ODM/OEM partners and optics-mechanical products development/DataAnalysis/research/process.

Profile

Deepak Bhagya

Personal info

Deepak Bhagya

If I have seen further than others, it is by standing upon the shoulders of giants.

Birthday: 21 Dec 1984
Phone number: +886
Website: https://bobobo746.blogspot.com
E-mail: 2dkjd1k@gmail.com

RESUME

Know more about my past


Employment

  • 2016-future

    https://www.ixensor.com/ix_web/ @ Optical-Software Programmer

    Optical-Signal algorithm and analysis: 1). Using smart phone’s front camera as optical-analysis device to observe color signal change. 2). Color signal change is based on the blood reacts with strips. 3.) By those signal change, trying to figure out a curve line to represent the bio-reacts on strips and use those feature to construct a measurement system. 4.) Trying to improve the bias, accuracy and precision. 5.) Issues fixed. Image process algorithm: 1.) Image Recognition: Analysis the image to make sure whether the optical device’s uniformity is qualified or not. Experiment Data Build: 1.) Using SQL to build Database for Experiment data. 2.) Producing API for co-workers to access and get some data source, reducing the data collecting time. 3.) Maintaining data base and trying to improve data schemas.

  • 2013-2016

    http://www.primax.com.tw/ @ Sr.Optical and Software Engineer

    1). Camera lens optical specifications define and analysis optical issue, likes the Flare, MTF(SFR), Alignment, Optical Center, and NG-sample analysis. 3). Lens focusing image recognition: Programming an application for machine to recognize the image and focus lens. 4). Con-call and report to customer, and vendor management.

  • 2010-2013

    www.Ledlink.com @ Optical Engineer

    1/ LED lighting lens module development, LED module development of TV backlight, new module development and spec. define. 2/ Optical design of LED lighting lens, jigs design, and solve process problems. 3/ Precision process development, new film materials analysis. 4/ New patent application . 5/ Optical simulation analysis

Education

  • 2006-2009

    University of NCUE @ graduated

    bachelor of science (physics)

  • *********.

Skills & My Love

Engineer
80%
software
WorkOut
91%
Fitting
Coding
95%
Python

Portfolio

My latest projects


顯示具有 pandas 標籤的文章。 顯示所有文章
顯示具有 pandas 標籤的文章。 顯示所有文章

2017年3月13日 星期一

Pandas Dataframe 語法


import pandas as pd
import numpy as np

                        pandas dataframe API
        pandas.DataFrame(data=None, index=None, columns=None, dtype=None, copy=False)
# attribute:(.即可)
'''DataFrame.size # 資料總數
  .shape # 幾乘幾的dataframe
  .values # 把 dataframe 轉成 2維 array
  .ndim # 維度
  .T # 轉置
  .dtypes # data types(看是整數還浮點數)
  .axes # 查看 index 跟 columns 名稱
  .ix # Lable 在該index 對應的資料,可以放index數字也可以放label文字 
  .loc # Lable 在該index 對應的資料 (只能放label文字 )
  [] # 第一個中括號,看columns的資料內容 ,後面補上的第二個括號是該columns對應的label
  .insert()# 插入:.insert(要插在第幾個column位置,安插的名稱,安插資訊內容)
'''            
df = pd.DataFrame(np.random.rand(4,3),index=['a','b','c','d'],columns =['A','B','C'])
print df.size
print df.shape
print df.values
print df.ndim
print df.dtypes
print df.axes
print df.ix[0]
print df.ix['a']
print df.loc['a']
print df['A']['a']

# method:(.小括號)
df = pd.DataFrame(np.random.randn(4,3),index=['a','b','c','d'],columns =['A','B','C'])
df2= pd.DataFrame(np.random.randn(4,1),index=['w','x','y','z'],columns =['A'])
'''
DataFrame
  <合併刪除>
  .add(other, axis='columns') # data相加,但是一定要columns名稱相同
  .append(other, ignore_index=False ) # 新增資料合併用,雷同merge
  .merge(right,how='inner') # 新增資料合併用 找相同columns然後從下面補上去,預設為交集(inner,可改為outer聯集
  .join(other,how='left') # 新增資料合併用,left:以原資料為主,other為新增,right則相反)
  .drop(labels) # 剔除label資料 (刪除columns: del df[] 沒有.點)

  <數值計算>
  .describe() # 幫忙計算資料的數量, mean, std,cv...等等
  .abs() # 絕對值
  .idxmax(axis) # 比較大小(依照axis :0就是ABC比,順序:橫向 1就是abcd比,順序:直立)
  .idxmin(axis)
  .mean(axis) # axis=0 A平均B平均C平均;axis=1 a平均b平均c平均d平均
  .min(axis) # axis=0 找A最小B最小C最小;axis=1 找a最小b最小c最小d最小
  .round([decimals]) # 取小數點幾位
  .std(axis=None) # 計算std ,依照指定的axis =0 或1
  .sum(axis= None) # 計算sum ,依照指定的axis =0 或1

  <獲取,查看資料>
  .get_values() # 等同於DataFrame.values
  .head(n) # 只列出前n列的資料 沒寫就是前五列
  .keys() # 只查看columns名稱

  <修改欄位>
  .reset_index(drop=True) # 如果今天index的lable順序因為合併變成雜亂,可以用這個重新從0開始排序(要寫true不然原先的index會留著)       
  .rename(index={ },columns= { }) # label與columns命名修改
  .swapaxes(axes1,axes2) # column ,index 互換
  .transpose() # column ,index 互換

  <修改內容>
  .df.shift(periods=1,axis=0) # shift,perios看要移動幾格, axis 看是移動直向還是橫向
  .set_value(index,col,value) # 設定資料內容, index,column都要是label value為要設定的資訊
  .sort_values(by=[],axis=0) # axis=0 依照ABC欄位去做abcd排序 by要填入column的label即A,B,C ,axis=1則相反 .  

  <存檔格式>
  .to_csv('.... .csv') # 轉成csv檔 改路徑就直接把路徑寫出最後補上.csv即可 (用pd.read_csv()讀檔案)
  .to_pickle('.... .pickle') # 轉成pickle檔 改路徑就直接把路徑寫出最後補上.pickle即可
  .to_json('.... .json') # 轉成json string檔 改路徑就直接把路徑寫出最後補上.json即可

  <更新>
  .update(other[]) # 更新other[] 中括號裡面上的是要更新column的lable。更新要確認index是否相同 否則更新無效     
'''     
print df
print df2
print df.append(df2,ignore_index =True)
print df.describe()
print df.drop('a')
print df.get_values()
print df.head(2)
print df.idxmax(0)
print df.idxmax(1)

#######移動shift 且新增資訊方式:
df3 =df.shift(axis=1)
print df3
val =[10,20,30,40]
label= ['a','b','c','d']     
for index,i in enumerate (val):
  df3 =df3.set_value(index =label[index],col='A',value=i)
print df3
########
print df.sort_values(by=['a','b','c','d'],axis=1)

pandas, series 其他語法

# dot 用法 : 矩陣相乘
s1 = pd.Series(np.arange(1,5)) 
s1.dot(s1)

# series- dictionary用法:
d ={'one':pd.Series([1,2,3],index=['a','b','c']),
  'two':pd.Series([4,5,6],index=['d','e','f']) }
print (d['one'])
df= pd.DataFrame(d)
print
print (df)
print
print(pd.DataFrame(d,index=['b','c','f']))

# list-dictionary用法:
t= [{'a':10, 'b':20},{'a':5,'b':300,'c':1}]
pd.DataFrame(t)

# DataFrame.from_item 用dictonary來幫dataframe的column命名:
df= pd.DataFrame.from_items([('a',[1,2,3]),('b',[4,5,6])])
print(df)
print
print(df.T)

# DataFrame.from_item 用dictonary方式來命名, 但加了orient就變成轉置只是強制要幫column命名:
df= pd.DataFrame.from_items([('a',[1,2,3]),('b',[4,5,6]),('c',[7,8,9]),('d',[10,11,12])],
  orient='index',columns=['one','two','three'])
df

# 可以做運算 也可以用flag做布林值判定
df['three'] =df['one']*df['two']
df['flag']= df['one']>2
df

# 刪除整個columns就 del (刪除整個index 用drop)
del df['three']
df

# 新增欄位直接寫要的欄位名稱 ,不過index內容全部統一(除非用condat合併才可以放入其他資訊)
df['date'] = '2017-03'
df

# 插入:insert(要插在第幾個column位置,安插的名稱,安插資訊內容)
df.insert(4,'james gordan',df['one'])
df

# 從欄位找資料:
print (df['one'])
print 
# 用loc,從 lable找資料 (也可以用iloc用index找資料):
print (df.loc['a']) # Same as : df.iloc[0]

# 切片用法:在df是切片用法,即切片起始0在空的lable那裏,所以a是1, 1:3 取兩個,頭不算 所以取2,3
df[1:3] # 與 d[:3]:從頭開始取到第3個不同含義

pandas concat 合併語法
pandas.concat(objs, axis=0, join='outer', join_axes=None, ignore_index=False, keys=None, levels=None, names=None)
# concat 兩個dataframe做合併 依照aixs軸設定 ,是新創的記憶體位置
df = pd.DataFrame(np.random.randn(4,3),index=['a','b','c','d'],columns =['A','B','C'])
df2= pd.DataFrame(np.random.randn(4,1),index=['w','x','y','z'],columns =['D'])
pd.concat([df,df2],ignore_index='True',axis=0)










這封郵件來自 Evernote。Evernote 是您專屬的工作空間,免費下載 Evernote

2017年3月10日 星期五

Demo_Pandas plot


%matplotlib
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
Plot
# simple plot
df = pd.DataFrame(np.random.randn(1000, 4), columns=['A', 'B', 'C', 'D'])
df.plot()
plt.figure();
df['A'].plot()
plt.figure();
df['A'].cumsum().plot()

# subplots 提供了多張圖示出現在一畫面的方式
df.plot(subplots=True, alpha =0.5,figsize=(6, 6))

# kde: density plots
df['A'].plot(kind='kde')
Bar plot
# 看DataFrame橫向: 另外也展示了堆疊的方式(stack)
df = pd.DataFrame(np.random.rand(10, 4), columns=['A', 'B', 'C', 'D'])
df.plot(kind='bar',alpha =0.8)
df.plot(kind='bar', stacked=True)

# 橫向bar堆疊(barh)
df.plot(kind='barh',alpha =0.8, stacked=True)
Histgram plot
# 看DataFrame縱向: A,B,C,D 的高斯分佈
df = pd.DataFrame(np.random.randn(100, 4), columns=['A', 'B', 'C', 'D'])
df.plot(kind='hist',alpha= 0.8)
df.plot(kind='hist',alpha= 0.5, stacked=True,bins= 50)
plt.figure()
df['A'].plot(kind='hist',bins= 10)

# df.diff().hist 提供了多張圖示出現在一畫面的方式
df.diff().hist(color='k', alpha=0.5, bins=30)

# subplots 提供了多張圖示出現在一畫面的方式
df.plot(kind='hist',subplots=True, alpha =0.5,figsize=(6,8),color='k',bins=30)
Area plot
# 都要是正數範圍;stack 可以改為透明
df = pd.DataFrame(np.random.rand(10, 4), columns=['A', 'B', 'C', 'D'])
df.plot(kind='area',alpha=0.5)
df.plot(kind='area', stacked=False)
Scatter plot
# simple scatter plot
df = pd.DataFrame(np.random.rand(50, 6), columns=['A', 'B', 'C', 'D','E','F'])
df.plot(kind='scatter', x='A', y='B')

# a3 為 A,B,C 對應E,F,G散佈圖
a1 = df.plot(kind='scatter', x='A', y='B',color='DarkBlue', label='Group 1')
a2 = df.plot(kind='scatter',x='C',y='D',color='DarkGreen', label='Group 2',ax = a1 )
a3 = df.plot(kind='scatter',x='E',y='F',color='k', label='Group 3',alpha =0.6 ,ax = a2 )

# s為圓點大小;c代表顏色用C的資料點代表顏色強度;colormap沒寫則預設黑色
df.plot(kind='scatter', x='A', y='B',c='C', colormap='OrRd', s=60)

# s為圓點大小,用C資料來改變點大小
df.plot(kind='scatter', x='A', y='B',c='k', s=df['C']*200)

# 六角形
df.plot(kind='hexbin', x='A', y='B', gridsize=15)

                                                                       Other Example(共用)
scatter_matrix: 展示了matrix的比較圖. 
e.g: A資料自己的常態分佈圖或是A,B . A,C . A,D 的散佈圖
from pandas.tools.plotting import scatter_matrix
df = pd.DataFrame(np.random.randn(1000, 4), columns=['A', 'B', 'C', 'D'])
scatter_matrix(df, alpha=0.2, figsize=(6, 6), diagonal='kde')

增加右邊y軸數值
df = pd.DataFrame(np.random.randn(1000, 4), columns=['A', 'B', 'C', 'D'])
df.A.plot(c='r')
df.B.plot(secondary_y=True, style='g')

增加右邊y軸數值與標籤
df = pd.DataFrame(np.random.randn(1000, 4), columns=['A', 'B', 'C', 'D'])
df= df.cumsum()
ax = df.plot(secondary_y=['A', 'B'])
ax.set_ylabel('CD scale')
ax.right_ax.set_ylabel('AB scale')

針對各資料設定顏色
df = pd.DataFrame(np.random.randn(1000, 4), columns=['A', 'B', 'C', 'D'])
df= df.cumsum()
with pd.plot_params.use('x_compat',True):
  df.A.plot(c='k')
  df.B.plot(c='m')
  df.C.plot(c='y')
  df.D.plot(c='grey')
  
提供了多張圖示出現在一畫面的方式
df = pd.DataFrame(np.random.randn(1000, 4), columns=['A', 'B', 'C', 'D'])
df= df.cumsum()
df.plot(subplots=True, figsize=(6, 6));

df = pd.DataFrame(np.random.randn(1000, 4), columns=['A', 'B', 'C', 'D'])
df= df.cumsum()
# subplot 排列方法 :layout=(2, 3)->(raw,column):
df.plot(subplots=True, layout=(2, 3), figsize=(6, 6), sharex=False);
# subplot 排列方法 :指定哪個raw哪個column放哪個資料:
fig, axes = plt.subplots(nrows=2, ncols=2)
df['A'].plot(ax=axes[0,0],c='k') ; axes[0,0].set_title('A');
df['B'].plot(ax=axes[0,1],c='k',alpha =0.7); axes[0,1].set_title('B');
df['C'].plot(ax=axes[1,0],c='k',alpha= 0.4); axes[1,0].set_title('C');
df['D'].plot(ax=axes[1,1],c='k',alpha= 0.1); axes[1,1].set_title('D');

subplot ,增加cv bias mean等的資訊在table欄位
from pandas.tools.plotting import table
df = pd.DataFrame(np.random.randn(1000, 4), columns=['A', 'B', 'C', 'D'])
df= df.cumsum()

fig,ax = plt.subplots(1, 1)
# describe():會幫忙算出cv bias mean...
# table 用來顯示欄位用的
table(ax, np.round(df.describe(), 2),loc='upper left', colWidths=[0.1, 0.1, 0.1,0.1])
df.plot(ax=ax,figsize=(10, 10))
 colormap
from pandas.tools.plotting import table
df = pd.DataFrame(np.random.randn(1000, 4), columns=['A', 'B', 'C', 'D'])
df= df.cumsum()
df.plot(colormap='Greens')










這封郵件來自 Evernote。Evernote 是您專屬的工作空間,免費下載 Evernote

2017年2月6日 星期一

python pandas 轉list 或 array

網路上很多人推崇pandas,但我覺得他還是有它不方便的地方,先前要從txt檔轉pickle檔pandas就沒有什麼方法可以直接查找,還是要做一次轉手.
今天在畫圖的時候,發現pandas 在cuffkinks上面是非常好用沒錯,但是如果我要用plotly而不是cufflinks的話就不是那麼方便了
至少就我目前還不會啦...
所以我只能將pandas 轉 array (順便也附帶如果要轉list的方法)

df = pd.DataFrame(np.random.randn(50,1))


# 轉array:
df[0].as_matrix()
   
# 轉list:
df['0'].values.tolist()

這封郵件來自 Evernote。Evernote 是您專屬的工作空間,免費下載 Evernote

python Pandas資料的刪除

資料的刪除基本上都是和網路上大家提到的方法一樣, 都是用drop的方式
但是我到的問題是:

假設我今天是有一堆數據依序讀出來然後存成了packle檔,(之後會再補上完整程式碼)
但是我必須要刪掉其中一行的數據,該怎辦?
一般是直接刪掉沒問題,但是我因為行沒有命名,主要是因為我存了一堆數據沒有必要去餵牠們命名,他們就只是我要做資料分析的訊號數據而已,如:


當刪除第2行的時候,之後就會變成 0 ,1,3 這並不是我要的
查了文檔發現並沒有針對columns做重新default的設定 只有index
所以我換了方向,只好先將原本的dataframe做轉置,然後再利用set_index的方式把 0,1,3變成 0,1,2

只是記得要再轉置回來 


原始碼:

import pandas as pd
import numpy as np
d = pd.DataFrame(np.random.rand(3,4)*10)
 
d
 
r=d.T
 
rr =r.drop([1],axis= 0)
 
rr
 
rrr =rr.reset_index(drop= True)
# drop= true will reset the index order as default
 
rrr
 
rrr.T
 
rrr.iloc[2]

這封郵件來自 Evernote。Evernote 是您專屬的工作空間,免費下載 Evernote

Services

What can I do


Branding

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Web Design

Quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Donec sit amet venenatis ligula. Aenean sed augue scelerisque.

Graphic Design

Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident.

Development

Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident.

Photography

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod. Donec sit amet venenatis ligula. Aenean sed augue scelerisque, dapibus risus sit amet.

User Experience

Quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Donec sit amet venenatis ligula. Aenean sed augue scelerisque, dapibus risus sit amet.

Contact

Get in touch with me


Adress/Street

12 Street West Victoria 1234 Australia

Phone number

+(12) 3456 789

Website

www.johnsmith.com