Reputation: 917
I have a .dat file which I first want to convert into a .csv file and then plot some of the rows against time, my scripts is as follows :
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()
I executed the script with python csv_flash_dat_file.py flash.dat
and got the following error :
File "csv_flash_dat_file.py", line 46
dataframe.plot(x='#time', 'Nuclear_Burning', style='r')
SyntaxError: non-keyword arg after keyword arg
I don't see the apparent reason to find the error, please help me fix this.
Upvotes: 2
Views: 1776
Reputation: 10841
The argument 'Nuclear_Burning' follows a keyword argument x
. Once you start using keywords in an argument list, you have to keep on using keyword arguments.
Upvotes: 4
Reputation: 1654
It's just what it says. You can't pass non-keyword arguments after keyword arguments. If you have something like x='#time', that's a keyword argument, and all of those have to come at the end of the argument list.
Upvotes: 4