我有一个 .dat 文件,我首先想将其转换为 .csv 文件,然后根据时间绘制一些行,我的脚本如下:
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', 'dens@max_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
我没有看到找到错误的明显原因,请帮我解决这个问题。
最佳答案
参数“Nuclear_Burning”跟在关键字参数 x
之后。一旦开始在参数列表中使用关键字,就必须继续使用关键字参数。
关于python - 没有明显原因的语法错误 : non-keyword arg after keyword arg,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39302705/