dict 형식 이용하여 변수명 자동 설정하기. [2018.09.13]

Posted by 센큐
2018. 9. 13. 15:56 Mathematica&Python

vars()['name {}'.format(variable)] = 1    #name variable  이라는 variable에 1이 들어간다.

globals()['name {}'.format(variable)] = 2    #name variable  이라는 global variable에 2가 들어간다.



ex)

a=1

vars()['name_{}'.format(a)]=1

print name_a

==> 1 출력.


matplotlib.pyplot 이용하여 그래프 꾸미기 [2018.09.12]

Posted by 센큐
2018. 9. 13. 00:04 Mathematica&Python

fig = matplotlib.pyplot.figure(1)    #figure 1번 생성.

ax = fig.add_subplot(3, 2, 1)    #3행 2열짜리 배열 중 1번째 자리에 ax이라는 subplot을 fig에 생성.

ax.plot(x, y)    #x array, y array 그래프 그리기.

ax.ticklabel_format(style = 'sci', scilimits = (-3, 5), axis='both', useMathText = True)    #'sci'entific notation, 10^(-3)~10^5 이외 구역 적용

ax.tick_params(direction='in')    #ticklabel 그래프 안쪽으로 넣기. (기본은 바깥쪽.)

pandas 이용하여 python에서 excel file의 data 다루기. [2018.09.12]

Posted by 센큐
2018. 9. 12. 15:14 Mathematica&Python

pandas라는 module이 필요.


import pandas    #importing "pandas" module.


##loading dataframe from excel file


xls = pandas.ExcelFile('file path')    #put the excel file whose name is "file path" into the variable "xls".


sheetname = xls.sheet_names    #put the list of sheet names into the variable "sheetname"


df = pandas.read_excel ( xls, sheet number )    #variable df :  dataframe of sheet number in the variable "xls"



##saving dataframe to excel file


xlsx = pandas.ExcelWriter('file path')    #make excel writer 'xlsx' whose name is 'file path'


df.to_excel(xlsx, 'sheet name')    #write the dataframe df to 'xlsx' with sheet name of 'sheet name'


xlsx.save()    #save the excel file 'xlsx'