python - 没有明显原因的语法错误 : non-keyword arg after keyword arg,

标签 python csv pandas

我有一个 .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/

相关文章:

python - 平均数从最高到最低

python - 如何让 CSV 阅读器读取内存文件?

python - 交替大写和小写字符

python - 如何使用 Python 将 CSV 转换为 JSON?

python - Flask 的子域?

python - 使用月平均值的 Pandas fillna 缺失小时时间点数据的方法

python - 使用 Pandas 聚合数据并保留表结构和列名的更好方法

python - 不同的成对加法迭代失败 Python

python - 使用python将标题添加到制表符分隔的csv文件

python - 将 df.value_counts 写入新文件