python is bugging

Piet van Oostrum piet-l at vanoostrum.org
Sat Sep 21 17:47:53 EDT 2019


Dave Martin <dschwartz0705 at gmail.com> 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 <piet-l at vanoostrum.org>
WWW: http://piet.vanoostrum.org/
PGP key: [8DAE142BE17999C4]



More information about the Python-list mailing list