2016-09-03 1 views
2

.csv 파일로 변환하고 시간에 따라 일부 행을 플롯하려는 .dat 파일이 있습니다. 스크립트는 다음과 같습니다. SyntaxError : 키워드 인수 뒤의 키워드가 아닌 인수 arg (명백한 이유 없음)

import pandas as pd 
import numpy as np 
from sys import argv 
from pylab import * 


import csv 



script, filename = argv 

txt = open(filename) 

print "Here's your file %r:" % filename 
print txt.read() 

# read flash.dat to a list of lists 
datContent = [i.strip().split() for i in open("./flash.dat").readlines()] 

# write it as a new CSV file 
with open("./flash.csv", "wb") as f: 
    writer = csv.writer(f) 
    writer.writerows(datContent) 



def your_func(row): 
    return (row['global_beta']) 


columns_to_keep = ['#time', 'global_beta', 'max_dens', 'max_temp', '[email protected]_temp'] 
dataframe = pd.read_csv("./flash.csv", usecols=columns_to_keep) 



dataframe['Nuclear_Burning'] = dataframe.apply(your_func, axis=1) 



pd.set_option('display.height', 1000) 
pd.set_option('display.max_rows', 1000) 
pd.set_option('display.max_columns', 500) 
pd.set_option('display.width', 1000) 

dataframe.plot(x='#time', 'Nuclear_Burning', style='r') 

print dataframe 

show() 

나는 python csv_flash_dat_file.py flash.dat으로 스크립트를 실행하고 다음과 같은 오류 있어요 :

File "csv_flash_dat_file.py", line 46 
    dataframe.plot(x='#time', 'Nuclear_Burning', style='r') 
SyntaxError: non-keyword arg after keyword arg 

내가 오류를 찾기 위해 이유없이 표시되지 않는이, 내가이 문제를 해결하는 데 도움 바랍니다.

답변

3

'Nuclear_Burning'인수는 키워드 인수 x 다음에옵니다. 인수 목록에서 키워드를 사용하기 시작하면 키워드 인수를 계속 사용해야합니다.

+0

오, 물론 지금은 y = 'Nuclear_Burning' – bhjghjh

4

그것은 그것이 말하는 것입니다. 키워드 인수 뒤에 키워드가 아닌 인수를 전달할 수 없습니다. x = '# time'과 같은 것을 가지고 있다면 그것은 키워드 인수이고, 그것들 모두는 인수 목록의 끝에 올 필요가 있습니다.

관련 문제