python - Syntax error when converting from float64 to integer -


i'm trying use excel data in pandas , have convert float64 data integer type, keep getting syntax errors. please note, complete novice programming languages, i'd appreciate as possible - it's taken me week figure out how open excel file in pandas, , i'm having problems getting format can use in matplotlib. code have used follows, hope can help...

from pandas import excelfile import pandas pd # create excelfile object xlsx = excelfile('filename.xlsx') xlsx.parse(sheetname, parse_cols=6, index_col=none, na_values= ['na'] # convert float data types integer spectral type = spectral type.astype('int') 

when run get:

spectral type = spectral type.astype('int')                 ^ syntaxerror: invalid syntax 

what doing wrong?

is there better way access , use excel data can create graph in matplotlib?

re comment in response unutbu, data of form:

type   value1   time1  value2   time2  value3   time3  m0  8.87    41.11   8.41    41.11   8.16    65.78; 

continuing values m1 m6:

m6     13.95  4392.03  14.41 10395.13  14.66 25988.32 

running script:

`from pandas import excelfile` `import pandas pd` `# create excelfile object` `xlsx = excelfile('filename.xlsx')` `xlsx.parse(sheetname', parse_cols=6, index_col=none, na_values= ['na'])` `df` 

(with addition of column names specified in parse action)

returns following output:

<class 'pandas.core.frame.dataframe'> int64index: 11 entries, 0 10 data columns: spectral type 10 non-null values limiting magnitude (1.3") 10 non-null values exposure time @ 1.3", sec 10 non-null values limiting magnitude (2.0") 10 non-null values exposure time @ 2.0", sec 10 non-null values limiting magnitude (2.5") 10 non-null values exposure time @ 2.5", sec 10 non-null values dtypes: float64(6), object(1)`

so, questions need ask are:

  1. is necessary change data type limiting magnitude , exposure time columns, given data decimal numbers?

  2. i need keep spectral type column is; how do this?

  3. what do able put data in proper tabular format, can graph it?

if spectral type column name in xlsx, try:

import pandas pd # create excelfile object xlsx = pd.excelfile('filename.xlsx') df = xlsx.parse('sheetname', parse_cols=6, index_col=none, na_values= ['na']) 

the spectral type column,

df['spectral type'] 

is of dtype object , contains values such m0. these strings. whatever case, dtype can not converted int. why

df['spectral type'] = df['spectral type'].astype('int') 

was raising error. if instead, wish convert column of dtype float int then

df['limiting magnitude (1.3")'] = df['limiting magnitude (1.3")'].astype('int') 

would work -- assuming i've got name of column correct.


is necessary change data type limiting magnitude , exposure time columns, given data decimal numbers?

at end of output posted, pandas reports

dtypes: float64(6), object(1) 

this says of 7 columns in dataframe, 6 of dtype float64 , 1 of dtype object. i'm guessing names of columns limiting magnitudes , exposure times of dtype float64, , spectral type of dtype object.

if guess right, should not need change type of limiting magnitudes , exposure times if want manipulate them float64s.


i need keep spectral type column is; how do this?

i don't understand question. please elaborate?


what do able put data in proper tabular format, can graph it?

your data can printed in tabular format this:

pd.set_option('display.max_columns', 7) print(df) 

to make plot, use matplotlib. pandas has functions plotting.


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -