Re: Python shows error on line 15 that i cant fix
On Sat, Sep 21, 2019 at 9:01 PM Michael Torrie wrote: > > On 9/21/19 12:51 PM, Dave Martin wrote: > > You seem to have the expectation that you know more about coding than > > me and that you can insult me without me retaliating. If I were you, > > I would leave this forum and never respond to another person question > > again, if you think that you can rudely ransack your way through what > > is supposed to be a helpful tool. > > Not so. He was not rude nor was he insulting. In fact he was downright > patient. You've been asked several times to read the tutorial (or > relevant parts of it) as that teaches you some things you have to know > in order to use Python. I'm sorry that rather than do that you chose to > react poorly to the good advice you were given. Thank you very much Michael and Chris! That was very kind of you. -- boB -- https://mail.python.org/mailman/listinfo/python-list
Re: [Tutor] Most efficient way to replace ", " with "." in a array and/or dataframe
On 21Sep2019 20:42, Markos wrote: I have a table.csv file with the following structure: , Polyarene conc ,, mg L-1 ,,, Spectrum, Py, Ace, Anth, 1, "0,456", "0,120", "0,168" 2, "0,456", "0,040", "0,280" 3, "0,152", "0,200", "0,280" I open as dataframe with the command: data = pd.read_csv ('table.csv', sep = ',', skiprows = 1) [...] And the data_array variable gets the fields in string format: [['0,456' '0,120' '0,168'] [...] Please see the documentation for the read_csv function here: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_csv.html?highlight=read_csv#pandas.read_csv In particular, because you have values formatted in the European style with "," for the decimal marker (and possibly "." for the thousands marker), you want to set the "decimal=" parameter of read-csv to ",". This is better than trying to mangle the data yourself, better to just correctly specify the dialect (i.e. set decimal= in your call). Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list
Re: Python shows error on line 15 that i cant fix
On 9/21/19 12:51 PM, Dave Martin wrote: > You seem to have the expectation that you know more about coding than > me and that you can insult me without me retaliating. If I were you, > I would leave this forum and never respond to another person question > again, if you think that you can rudely ransack your way through what > is supposed to be a helpful tool. Not so. He was not rude nor was he insulting. In fact he was downright patient. You've been asked several times to read the tutorial (or relevant parts of it) as that teaches you some things you have to know in order to use Python. I'm sorry that rather than do that you chose to react poorly to the good advice you were given. -- https://mail.python.org/mailman/listinfo/python-list
Re: Most efficient way to replace "," with "." in a array and/or dataframe
On 2019-09-22 00:42, Markos wrote: Hi, I have a table.csv file with the following structure: , Polyarene conc ,, mg L-1 ,,, Spectrum, Py, Ace, Anth, 1, "0,456", "0,120", "0,168" 2, "0,456", "0,040", "0,280" 3, "0,152", "0,200", "0,280" I open as dataframe with the command: data = pd.read_csv ('table.csv', sep = ',', skiprows = 1) and the variable "data" has the structure: Spectrum, Py, Ace, Anth, 0 1 0,456 0,120 0,168 1 2 0,456 0,040 0,280 2 3 0,152 0,200 0,280 I copy the numeric fields to an array with the command: data_array = data.values [:, 1:] And the data_array variable gets the fields in string format: [['0,456' '0,120' '0,168'] ['0,456' '0,040' '0,280'] ['0,152' '0,200' '0,280']] The only way I found to change comma "," to dot "." was using the method replace(): for i, line in enumerate (data_array): data_array [i] = ([float (element.replace (',', '.')) for element in data_array [i]]) But I'm wondering if there is another, more "efficient" way to make this change without having to "iterate" all elements of the array with a loop "for". Also I'm also wondering if there would be any benefit of making this modification in dataframe before extracting the numeric fields to the array. Please, any comments or tip? I'd suggest doing all of the replacements in the CSV file first, something like this: import re with open('table.csv') as file: csv_data = file.read() # Convert the decimal points and also make them look numeric. csv_data = re.sub(r'"(-?\d+),(\d+)"', r'\1.\2', csv_data) with open('fixed_table.csv', 'w') as file: file.write(csv_data) -- https://mail.python.org/mailman/listinfo/python-list
Book for Long Short-Term Memory for Sequential Data
Please, help me the title of a book about Deep Learning with the Recurrent Neural Network network structure using Long Short-term Memory for Sequential Data (time-series data). The R or Python language is OK. I need a book like hand-on because I do not work in information technology. Thank you so much for your help. -- https://mail.python.org/mailman/listinfo/python-list
Most efficient way to replace "," with "." in a array and/or dataframe
Hi, I have a table.csv file with the following structure: , Polyarene conc ,, mg L-1 ,,, Spectrum, Py, Ace, Anth, 1, "0,456", "0,120", "0,168" 2, "0,456", "0,040", "0,280" 3, "0,152", "0,200", "0,280" I open as dataframe with the command: data = pd.read_csv ('table.csv', sep = ',', skiprows = 1) and the variable "data" has the structure: Spectrum, Py, Ace, Anth, 0 1 0,456 0,120 0,168 1 2 0,456 0,040 0,280 2 3 0,152 0,200 0,280 I copy the numeric fields to an array with the command: data_array = data.values [:, 1:] And the data_array variable gets the fields in string format: [['0,456' '0,120' '0,168'] ['0,456' '0,040' '0,280'] ['0,152' '0,200' '0,280']] The only way I found to change comma "," to dot "." was using the method replace(): for i, line in enumerate (data_array): data_array [i] = ([float (element.replace (',', '.')) for element in data_array [i]]) But I'm wondering if there is another, more "efficient" way to make this change without having to "iterate" all elements of the array with a loop "for". Also I'm also wondering if there would be any benefit of making this modification in dataframe before extracting the numeric fields to the array. Please, any comments or tip? Thanks you, Markos -- https://mail.python.org/mailman/listinfo/python-list
Re: python is bugging
Dave Martin writes: > On Saturday, September 21, 2019 at 12:44:27 PM UTC-4, Brian Oney wrote: >> On Sat, 2019-09-21 at 08:57 -0700, Dave Martin wrote: >> > On Saturday, September 21, 2019 at 11:55:29 AM UTC-4, Dave Martin >> > wrote: >> > > what does expected an indented block >> > >> > *what does an indented block mean? >> >> It means that the line of code belongs to a certain body as defined >> above its position. >> >> Please follow the tutorial. >> >> https://docs.python.org/3/tutorial/index.html > > df.to_csv(r"faststars.csv", index=None,header=True) > # starAbsMags=df['radial_velocity'] > > #GaiaPandasEscapeVelocityCode > > import pandas as pd > import numpy as np > from astropy.io import fits > import astropy > import matplotlib.pyplot as plt > > > #get the combined data and load the fits files > > fits_filename="Gaia_DR2/gaiadr2_100pc.fits" > df=pd.DataFrame() > with fits.open(fits_filename) as data: > df=pd.DataFrame(data[1].data) > df.columns=[c.lower() for c in df.columns] > print("Columns.") > print(df.columns.values) > print("n/n") > #print out some data meta info to see what we're working with > print("Number of stars:") > nstars=len(df) > print(nstars) > distances = (df['parallax']/1000) > starAbsMags =df['phot_g_mean_mag'] > df = df[(df.parallax_over_error > 10 ) ] > print("Left after filter: " +str(len(df)/float(nstars)*100)+" %") > df.hist(column='radial_velocity') > #fastdf=df[(df.radial_velocity > 200) | (df.radial_velocity < -200)] > fastdf=df[(df.radial_velocity > 550)|(df.radial_velocity<-550)] > print(len(fastdf)) > #print(fastdf)# starTemps=df['astrometric_weight_al'] > # df.plot.scatter("radial_velocity", "astrometric_weight_al", s=1, > c="radial_velocity", colormap="plasma") > # #df=df[(df.radial_velocity>=-550)] > # #plt.axis([0,400,-800,-550]) > # #plt.axis([0,400,550,800]) > # plt.xlabel('weight(Au)') > # plt.ylabel('Speed') > # plt.title('Gaia Speed vs Weight') > > this is my code the error is on line 15 1) What is line 15? 2) Always copy/paste the complete error message with your question. 3) Your with body is not indented: with fits.open(fits_filename) as data: df=pd.DataFrame(data[1].data) df.columns=[c.lower() for c in df.columns] print("Columns.") print(df.columns.values) But how should WE know how many lines belong to the body of the with statements? You should know that and indicate that with the indentation as described in the tutorial. And then there's also a strange line: c="radial_velocity", colormap="plasma") Probably meant to be a continuation of the previous, commented line, but as written it isn't. -- Piet van Oostrum WWW: http://piet.vanoostrum.org/ PGP key: [8DAE142BE17999C4] -- https://mail.python.org/mailman/listinfo/python-list
Re: python is bugging
Dave Martin writes: > On Saturday, September 21, 2019 at 11:55:29 AM UTC-4, Dave Martin wrote: >> what does expected an indented block > > *what does an indented block mean? From the tutorial, https://docs.python.org/3/tutorial/ 3.2. First Steps Towards Programming: The body of the loop is indented: indentation is Python’s way of grouping statements. At the interactive prompt, you have to type a tab or space(s) for each indented line. In practice you will prepare more complicated input for Python with a text editor; all decent text editors have an auto-indent facility. When a compound statement is entered interactively, it must be followed by a blank line to indicate completion (since the parser cannot guess when you have typed the last line). Note that each line within a basic block must be indented by the same amount. -- Piet van Oostrum WWW: http://piet.vanoostrum.org/ PGP key: [8DAE142BE17999C4] -- https://mail.python.org/mailman/listinfo/python-list
Re: Document Entire Apps
On 15 Sep 2019 07:00, Sinardy Gmail wrote: I understand that we can use pydoc to document procedures how about the relationship between packages and dependencies ? ==》 Check out snakefood to generate dependency graphs: http://furius.ca/snakefood/. Also, did you discover sphinx already? -- https://mail.python.org/mailman/listinfo/python-list
Re: python is bugging
On 22/09/19 5:08 AM, Dave Martin wrote: On Saturday, September 21, 2019 at 12:44:27 PM UTC-4, Brian Oney wrote: On Sat, 2019-09-21 at 08:57 -0700, Dave Martin wrote: On Saturday, September 21, 2019 at 11:55:29 AM UTC-4, Dave Martin wrote: what does expected an indented block *what does an indented block mean? It means that the line of code belongs to a certain body as defined above its position. Please follow the tutorial. ... this is my code the error is on line 15 Did you follow the tutorial? Is it easy (for *volunteer* helpers) to work-out which is line 15? Back to the original question: Is the (loop) code actually indented? -- Regards =dn -- https://mail.python.org/mailman/listinfo/python-list
Re: Python shows error on line 15 that i cant fix
On Sun, Sep 22, 2019 at 4:56 AM Dave Martin wrote: > > On Saturday, September 21, 2019 at 2:46:15 PM UTC-4, boB Stepp wrote: > > On Sat, Sep 21, 2019 at 1:01 PM Dave Martin wrote: > > > > > > On Saturday, September 21, 2019 at 1:33:12 PM UTC-4, Terry Reedy wrote: > > > > On 9/21/2019 11:53 AM, Dave Martin wrote: > > [...] > > > > > #get the combined data and load the fits files > > > > > > > > > > fits_filename="Gaia_DR2/gaiadr2_100pc.fits" > > > > > df=pd.DataFrame() > > > > > with fits.open(fits_filename) as data: > > > > > df=pd.DataFrame(data[1].data) > > > > > > > > A 'with' statement is a compound statement. It must be followed by a > > > > 'suite', which usually consists of an indented block of statements. > > > > This is line 17 from the first non-blank line you posted. > > [...] > > > > > Can you provide an example of how to use the suite feature. Thank you. > > > > Dave, you seem to have some expectation that you should be given the > > answer. That is not how help is given in this forum. You are > > expected to be doing the needed to work before being helped further. > > You have been referred to the tutorial multiple times. Please read > > it! Indentation is so fundamental to structuring Python code that it > > is clear that you need grounding in Python fundamentals. Otherwise > > you are essentially Easter-egging through a code sample that you have > > no true understanding of. > > > > If you must continue to Easter-egg Python instead of reading the > > tutorial (or something equivalent) then check the section of the > > tutorial on files. You will find examples of the use of "with" there. > > > You seem to have the expectation that you know more about coding than me and > that you can insult me without me retaliating. If I were you, I would leave > this forum and never respond to another person question again, if you think > that you can rudely ransack your way through what is supposed to be a helpful > tool. > When you ask for help on a public forum, it's usually best to start by reading the tutorials yourself. http://www.catb.org/~esr/faqs/smart-questions.html boB is absolutely correct here: you need to learn the basics before further questions will be truly productive. We are not here to read aloud from the tutorial to you. Once you have a basic understanding of Python's structure, you will be far better able to ask questions and understand the answers. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Python shows error on line 15 that i cant fix
Am 21.09.2019 um 19:57 schrieb Dave Martin: > Can you provide an example of how to use the suite feature. Thank you. > There is no suite feature, Terry just tried to explain indented blocks to you in simple words. Really, indented blocks are one of the most basic aspects of Python. You *need* to read the tutorial as it has been suggested three times now. Anyway, given the following code: if name == "Dave": print("Hello Dave") print("How are you?) Programming languages in general cannot exactly understand what that code means. It could mean: "Say 'Hello Dave' and then 'How are you?" if the name is Dave. But it could also mean: "Say 'Hello Dave' if the name is Dave and then say "How are you?" what ever the name is. So, we need to tell Python which command should be executed if the name is Dave and which not. Some languages solves this with block markers: if name == "Dave" then print("Hello Dave") print("How are you?) endif Or for the other meaning: if name == "Dave" then print("Hello Dave") endif print("How are you?) Python uses indented blocks to make clear which commands belong together. Indentations are runs of whitespaces (of equal length) at the beginning of the line: if name == "Dave": print("Hello Dave") print("How are you?") Or for the other meaning: if name == "Dave": print("Hello Dave") print("How ar you"?) For your code that means, that you need to indent the lines that belong to the 'with' block This is wrong: with fits.open(fits_filename) as data: df=pd.DataFrame(data[1].data) ... What you need is this: with fits.open(fits_filename) as data: df=pd.DataFrame(data[1].data) ... ^-- See these spaces in front of the commands. That are indentations and all consecutive indented lines are an indented block. Please read the tutorial at https://docs.python.org/3/tutorial/index.html (fourth time now ;-) ) -- https://mail.python.org/mailman/listinfo/python-list
Re: Python shows error on line 15 that i cant fix
On Saturday, September 21, 2019 at 2:46:15 PM UTC-4, boB Stepp wrote: > On Sat, Sep 21, 2019 at 1:01 PM Dave Martin wrote: > > > > On Saturday, September 21, 2019 at 1:33:12 PM UTC-4, Terry Reedy wrote: > > > On 9/21/2019 11:53 AM, Dave Martin wrote: > [...] > > > > #get the combined data and load the fits files > > > > > > > > fits_filename="Gaia_DR2/gaiadr2_100pc.fits" > > > > df=pd.DataFrame() > > > > with fits.open(fits_filename) as data: > > > > df=pd.DataFrame(data[1].data) > > > > > > A 'with' statement is a compound statement. It must be followed by a > > > 'suite', which usually consists of an indented block of statements. > > > This is line 17 from the first non-blank line you posted. > [...] > > > Can you provide an example of how to use the suite feature. Thank you. > > Dave, you seem to have some expectation that you should be given the > answer. That is not how help is given in this forum. You are > expected to be doing the needed to work before being helped further. > You have been referred to the tutorial multiple times. Please read > it! Indentation is so fundamental to structuring Python code that it > is clear that you need grounding in Python fundamentals. Otherwise > you are essentially Easter-egging through a code sample that you have > no true understanding of. > > If you must continue to Easter-egg Python instead of reading the > tutorial (or something equivalent) then check the section of the > tutorial on files. You will find examples of the use of "with" there. > > > -- > boB Bob, You seem to have the expectation that you know more about coding than me and that you can insult me without me retaliating. If I were you, I would leave this forum and never respond to another person question again, if you think that you can rudely ransack your way through what is supposed to be a helpful tool. -Dave -- https://mail.python.org/mailman/listinfo/python-list
Re: Python shows error on line 15 that i cant fix
On Sat, Sep 21, 2019 at 1:01 PM Dave Martin wrote: > > On Saturday, September 21, 2019 at 1:33:12 PM UTC-4, Terry Reedy wrote: > > On 9/21/2019 11:53 AM, Dave Martin wrote: [...] > > > #get the combined data and load the fits files > > > > > > fits_filename="Gaia_DR2/gaiadr2_100pc.fits" > > > df=pd.DataFrame() > > > with fits.open(fits_filename) as data: > > > df=pd.DataFrame(data[1].data) > > > > A 'with' statement is a compound statement. It must be followed by a > > 'suite', which usually consists of an indented block of statements. > > This is line 17 from the first non-blank line you posted. [...] > Can you provide an example of how to use the suite feature. Thank you. Dave, you seem to have some expectation that you should be given the answer. That is not how help is given in this forum. You are expected to be doing the needed to work before being helped further. You have been referred to the tutorial multiple times. Please read it! Indentation is so fundamental to structuring Python code that it is clear that you need grounding in Python fundamentals. Otherwise you are essentially Easter-egging through a code sample that you have no true understanding of. If you must continue to Easter-egg Python instead of reading the tutorial (or something equivalent) then check the section of the tutorial on files. You will find examples of the use of "with" there. -- boB -- https://mail.python.org/mailman/listinfo/python-list
Re: Python shows error on line 15 that i cant fix
On Saturday, September 21, 2019 at 1:33:12 PM UTC-4, Terry Reedy wrote: > On 9/21/2019 11:53 AM, Dave Martin wrote: > > > > # starAbsMags=df['radial_velocity'] > > > > #GaiaPandasEscapeVelocityCode > > > > import pandas as pd > > import numpy as np > > from astropy.io import fits > > import astropy > > import matplotlib.pyplot as plt > > > > > > #get the combined data and load the fits files > > > > fits_filename="Gaia_DR2/gaiadr2_100pc.fits" > > df=pd.DataFrame() > > with fits.open(fits_filename) as data: > > df=pd.DataFrame(data[1].data) > > A 'with' statement is a compound statement. It must be followed by a > 'suite', which usually consists of an indented block of statements. > This is line 17 from the first non-blank line you posted. > > Please stop spamming the list with multiple posts. Do spend a few hours > reading the tutorial until you understand my answer. > https://docs.python.org/3/tutorial/index.html Also read > https://stackoverflow.com/help/minimal-reproducible-example > so you can ask better questions. > > I presume you got "SyntaxError: expected an indented block". > A minimal example getting this error is, for instance, > > while True: > a = 1 > > -- > Terry Jan Reedy Can you provide an example of how to use the suite feature. Thank you. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python shows error on line 15 that i cant fix
On 9/21/2019 11:53 AM, Dave Martin wrote: # starAbsMags=df['radial_velocity'] #GaiaPandasEscapeVelocityCode import pandas as pd import numpy as np from astropy.io import fits import astropy import matplotlib.pyplot as plt #get the combined data and load the fits files fits_filename="Gaia_DR2/gaiadr2_100pc.fits" df=pd.DataFrame() with fits.open(fits_filename) as data: df=pd.DataFrame(data[1].data) A 'with' statement is a compound statement. It must be followed by a 'suite', which usually consists of an indented block of statements. This is line 17 from the first non-blank line you posted. Please stop spamming the list with multiple posts. Do spend a few hours reading the tutorial until you understand my answer. https://docs.python.org/3/tutorial/index.html Also read https://stackoverflow.com/help/minimal-reproducible-example so you can ask better questions. I presume you got "SyntaxError: expected an indented block". A minimal example getting this error is, for instance, while True: a = 1 -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: python is bugging
On Saturday, September 21, 2019 at 12:44:27 PM UTC-4, Brian Oney wrote: > On Sat, 2019-09-21 at 08:57 -0700, Dave Martin wrote: > > On Saturday, September 21, 2019 at 11:55:29 AM UTC-4, Dave Martin > > wrote: > > > what does expected an indented block > > > > *what does an indented block mean? > > It means that the line of code belongs to a certain body as defined > above its position. > > Please follow the tutorial. > > https://docs.python.org/3/tutorial/index.html df.to_csv(r"faststars.csv", index=None,header=True) # starAbsMags=df['radial_velocity'] #GaiaPandasEscapeVelocityCode import pandas as pd import numpy as np from astropy.io import fits import astropy import matplotlib.pyplot as plt #get the combined data and load the fits files fits_filename="Gaia_DR2/gaiadr2_100pc.fits" df=pd.DataFrame() with fits.open(fits_filename) as data: df=pd.DataFrame(data[1].data) df.columns=[c.lower() for c in df.columns] print("Columns.") print(df.columns.values) print("n/n") #print out some data meta info to see what we're working with print("Number of stars:") nstars=len(df) print(nstars) distances = (df['parallax']/1000) starAbsMags =df['phot_g_mean_mag'] df = df[(df.parallax_over_error > 10 ) ] print("Left after filter: " +str(len(df)/float(nstars)*100)+" %") df.hist(column='radial_velocity') #fastdf=df[(df.radial_velocity > 200) | (df.radial_velocity < -200)] fastdf=df[(df.radial_velocity > 550)|(df.radial_velocity<-550)] print(len(fastdf)) #print(fastdf)# starTemps=df['astrometric_weight_al'] # df.plot.scatter("radial_velocity", "astrometric_weight_al", s=1, c="radial_velocity", colormap="plasma") # #df=df[(df.radial_velocity>=-550)] # #plt.axis([0,400,-800,-550]) # #plt.axis([0,400,550,800]) # plt.xlabel('weight(Au)') # plt.ylabel('Speed') # plt.title('Gaia Speed vs Weight') this is my code the error is on line 15 -- https://mail.python.org/mailman/listinfo/python-list
Re: python is bugging
On Sat, 2019-09-21 at 08:57 -0700, Dave Martin wrote: > On Saturday, September 21, 2019 at 11:55:29 AM UTC-4, Dave Martin > wrote: > > what does expected an indented block > > *what does an indented block mean? It means that the line of code belongs to a certain body as defined above its position. Please follow the tutorial. https://docs.python.org/3/tutorial/index.html -- https://mail.python.org/mailman/listinfo/python-list
Re: python is bugging
On Saturday, September 21, 2019 at 11:55:29 AM UTC-4, Dave Martin wrote: > what does expected an indented block *what does an indented block mean? -- https://mail.python.org/mailman/listinfo/python-list
python is bugging
what does expected an indented block -- https://mail.python.org/mailman/listinfo/python-list
Python shows error on line 15 that i cant fix
# starAbsMags=df['radial_velocity'] #GaiaPandasEscapeVelocityCode import pandas as pd import numpy as np from astropy.io import fits import astropy import matplotlib.pyplot as plt #get the combined data and load the fits files fits_filename="Gaia_DR2/gaiadr2_100pc.fits" df=pd.DataFrame() with fits.open(fits_filename) as data: df=pd.DataFrame(data[1].data) df.columns=[c.lower() for c in df.columns] print("Columns.") print(df.columns.values) print("n/n") #print out some data meta info to see what we're working with print("Number of stars:") nstars=len(df) print(nstars) distances = (df['parallax']/1000) starAbsMags =df['phot_g_mean_mag'] df = df[(df.parallax_over_error > 10 ) ] print("Left after filter: " +str(len(df)/float(nstars)*100)+" %") df.hist(column='radial_velocity') #fastdf=df[(df.radial_velocity > 200) | (df.radial_velocity < -200)] fastdf=df[(df.radial_velocity > 550)|(df.radial_velocity<-550)] print(len(fastdf)) #print(fastdf)# starTemps=df['astrometric_weight_al'] # df.plot.scatter("radial_velocity", "astrometric_weight_al", s=1, c="radial_velocity", colormap="plasma") # #df=df[(df.radial_velocity>=-550)] # #plt.axis([0,400,-800,-550]) # #plt.axis([0,400,550,800]) # plt.xlabel('weight(Au)') # plt.ylabel('Speed') # plt.title('Gaia Speed vs Weight') -- https://mail.python.org/mailman/listinfo/python-list