Re: [Tutor] Reading CSV files in Pandas

2013-10-20 Thread Manish Tripathi
Thanks Mark. I have already asked this question on StackOverflow but to no
avail. So thought of asking here.


On Sun, Oct 20, 2013 at 5:47 AM, Mark Lawrence wrote:

> On 19/10/2013 15:29, Manish Tripathi wrote:
>
> You are far more likely to get a response to the identical question that
> you've already asked on stackoverflow than you are here.
>
>
> --
> Roses are red,
> Violets are blue,
> Most poems rhyme,
> But this one doesn't.
>
> Mark Lawrence
>
> __**_
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/**mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Passing arguments?

2013-10-20 Thread Jenny Allar
I've written the code below the assignment, and I think I have everything
covered in terms of asking the user for the information I need and somehow
calculating costs, but I'm just ridiculously confused on the order and
placement of the functions and components of this program- specifically the
shiprate variable. Thank you in advance for any help.

This is my assignment:

Write a program that asks a user for the name of a product that they are
ordering online and its weight.  The program must calculate the cost of
shipping the product using the following cost structure.  If it weighs less
than 10 pounds the cost is $1.50 per pound, if it is 10 pounds or more and
less than 25 pounds then the cost is $1.45 per pound.  If the weight is 25
pounds or more the cost is $1.40 per pound.  You may get the data from the
user in main.  You must print the name of the product, the weight and the
cost of shipping in a separate function.



**NOTE:  ALWAYS USE “WHILE LOOPS” To Validate

*
*







# This program uses an if-else statement

# It asks for the name of a product and the weight of that product.

# It then determines the shipping cost as defined by the weight.

#

# Variable  Type  Purpose

# product   string  hold for name of product

# weight float   hold for weight of product

#


def main ():



product = input("Please enter the name of the product: ")

weight = int(input("Please enter the weight of the product: "))


print('Product:', product)

print('Weight:', weight)



if weight <= 10:

shiprate = 1.5

calc_weight_small(weight, shiprate)

elif weight >= 10 and weight <= 25:

shiprate = 1.45

calc_weight_medium(weight, shiprate)

else:

shiprate = 1.4

calc_weight_large(weight, shiprate)


# Calculate shipping cost for product less than 10 pounds

def cacl_weight_small(weight, shiprate):

shiprate = 1.5

total = weight * shiprate

# Calculate shipping cost for product between 10 and 25 pounds.

def calc_weight_medium(weight, shiprate):

shiprate = 1.45

total = weight * shiprate

# Calculate shipping cost for product over 25 pounds.

def calc_weight_large(weight, shiprate):

shiprate = 1.4

total = weight * shiprate



#

#This function calculates and prints the total cost

# based on the weight category the product falls into

# VariableType Purpose

#  weight   floatweight of product

#  shipratefloatcost per pound

#  total   floattotal cost to ship product

#





print ()

print ("The cost to ship", product, "is:$", format (total,
 '9,.2f'))











main ()
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Passing arguments?

2013-10-20 Thread Dominik George
Hi,

> I've written the code below the assignment, and I think I have everything
> covered in terms of asking the user for the information I need and somehow
> calculating costs, but I'm just ridiculously confused on the order and
> placement of the functions and components of this program- specifically the
> shiprate variable. Thank you in advance for any help.

so, you are confused. Cool ☺! But, what is your question ;)? Your
subject suggests it has something to do with passing arguments to a
script, but, umm… I do not see what this has to do with the rest of your
mail ;).

Also, please reformat your code in a readable manner, i.e. remove the
many empty lines, reformat function calls according to style guide, etc.

Cheers,
Nik

-- 
 Auf welchem Server liegt das denn jetzt…?
 Wenn es nicht übers Netz kommt bei Hetzner, wenn es nicht
gelesen wird bei STRATO, wenn es klappt bei manitu.

PGP-Fingerprint: 3C9D 54A4 7575 C026 FB17  FD26 B79A 3C16 A0C4 F296


signature.asc
Description: Digital signature
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Auto-response for your message to the "Tutor" mailing list

2013-10-20 Thread Dominik George
> Your message for tutor@python.org, the Python programming tutor list,
> has been received and is being delivered.  This automated response is
> sent to those of you new to the Tutor list, to point out a few
> resources that can help with answering your own questions, or improve
> the chances of getting a useful answer from the other subscribers.

Thank you, but…

…I have been a member of the list for many weeks now and have posted
quite a few messages. Is there a reason I am receiving this friendly
greeter more than once?

-nik

-- 
# apt-assassinate --help
Usage: apt-assassinate [upstream|maintainer] 

PGP-Fingerprint: 3C9D 54A4 7575 C026 FB17  FD26 B79A 3C16 A0C4 F296


signature.asc
Description: Digital signature
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Passing arguments?

2013-10-20 Thread Mark Lawrence

On 20/10/2013 09:31, Dominik George wrote:

Hi,

Also, please reformat your code in a readable manner, i.e. remove the
many empty lines, reformat function calls according to style guide, etc.

Cheers,
Nik



Not another case of the infamous double spaced google disease?  If yes 
it can be cured by reading, digesting and actioning this 
https://wiki.python.org/moin/GoogleGroupsPython.  Better still use a 
decent email client like Thunderbird.


--
Roses are red,
Violets are blue,
Most poems rhyme,
But this one doesn't.

Mark Lawrence

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Reading CSV files in Pandas

2013-10-20 Thread Matthew Ngaha
Does pandas do the same thing numpy does? I've never used them and
unsure of what they are about.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Reading CSV files in Pandas

2013-10-20 Thread Mark Lawrence

On 20/10/2013 11:30, Matthew Ngaha wrote:

Does pandas do the same thing numpy does? I've never used them and
unsure of what they are about.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor



Pandas uses numpy, as does many other Python packages.

From http://pandas.pydata.org/ "pandas is an open source, BSD-licensed 
library providing high-performance, easy-to-use data structures and data 
analysis tools for the Python programming language."


From http://www.numpy.org/ "NumPy is the fundamental package for 
scientific computing with Python. It contains among other things:


a powerful N-dimensional array object
sophisticated (broadcasting) functions
tools for integrating C/C++ and Fortran code
useful linear algebra, Fourier transform, and random number capabilities"

--
Roses are red,
Violets are blue,
Most poems rhyme,
But this one doesn't.

Mark Lawrence

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Passing arguments?

2013-10-20 Thread Dave Angel
On 20/10/2013 00:20, Jenny Allar wrote:

Earlier, you have managed to send your emails as text, but this time
you blew it and used html.  That's probably what makes the code
doublespaced in the newsgroup.  It also means that most of us see

> I've written the code below the assignment, and I think I have everything
> covered in terms of asking the user for the information I need and somehow
> calculating costs, but I'm just ridiculously confused on the order and
> placement of the functions and components of this program- specifically the
> shiprate variable. Thank you in advance for any help.
>
> This is my assignment:
>
> Write a program that asks a user for the name of a product that they are
> ordering online and its weight.  The program must calculate the cost of
> shipping the product using the following cost structure.  If it weighs less
> than 10 pounds the cost is $1.50 per pound, if it is 10 pounds or more and
> less than 25 pounds then the cost is $1.45 per pound.  If the weight is 25
> pounds or more the cost is $1.40 per pound.  You may get the data from the
> user in main.  You must print the name of the product, the weight and the
> cost of shipping in a separate function.


>
>
>
> **NOTE:  ALWAYS USE “WHILE LOOPS” To Validate
>
> *
> *
>
>
>
>
>
>
>
> # This program uses an if-else statement
>
> # It asks for the name of a product and the weight of that product.
>
> # It then determines the shipping cost as defined by the weight.
>
> #
>
> # Variable  Type  Purpose
>
> # product   string  hold for name of product
>
> # weight float   hold for weight of product
>
> #
>
>
> def main ():
>
>
>
> product = input("Please enter the name of the product: ")
>
> weight = int(input("Please enter the weight of the product: "))
>
>
> print('Product:', product)
>
> print('Weight:', weight)
>
>
>
> if weight <= 10:
>
> shiprate = 1.5
>
> calc_weight_small(weight, shiprate)
>
> elif weight >= 10 and weight <= 25:
>
> shiprate = 1.45
>
> calc_weight_medium(weight, shiprate)
>
> else:
>
> shiprate = 1.4
>
> calc_weight_large(weight, shiprate)
>
>
> # Calculate shipping cost for product less than 10 pounds
>
> def cacl_weight_small(weight, shiprate):
>
> shiprate = 1.5
>
> total = weight * shiprate
>
> # Calculate shipping cost for product between 10 and 25 pounds.
>
> def calc_weight_medium(weight, shiprate):
>
> shiprate = 1.45
>
> total = weight * shiprate
>
> # Calculate shipping cost for product over 25 pounds.
>
> def calc_weight_large(weight, shiprate):
>
> shiprate = 1.4
If you had removed this line, the function would have served the need,
and you wouldn't need the other two.  One function called calc_weight
would do it.

>
> total = weight * shiprate
>
>
>
> #
>
> #This function calculates and prints the total cost
>
> # based on the weight category the product falls into
>
> # VariableType Purpose
>
> #  weight   floatweight of product
>
> #  shipratefloatcost per pound
>
> #  total   floattotal cost to ship product
>
> #
>
>
>
>
>
> print ()
>
> print ("The cost to ship", product, "is:$", format (total,
>  '9,.2f'))
>
>
>
>
>
>
>
>
>
>
>
> main ()
>
>
'Weight:', weight)
>  class="MsoNormal">    if weight <= 10:        
> shiprate = 1.5        calc_weight_small(weight, 
> shiprate)
>     elif weight >= 10 and weight <= 25: class="MsoNormal">        shiprate = 1.45        
> calc_weight_medium(weight, shiprate)    else:



-- 
DaveA


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Auto-response for your message to the "Tutor" mailing list

2013-10-20 Thread Dave Angel
On 20/10/2013 04:34, Dominik George wrote:

>> Your message for tutor@python.org, the Python programming tutor list,
>> has been received and is being delivered.  This automated response is
>> sent to those of you new to the Tutor list, to point out a few
>> resources that can help with answering your own questions, or improve
>> the chances of getting a useful answer from the other subscribers.
>
> Thank you, but…
>
> …I have been a member of the list for many weeks now and have posted
> quite a few messages. Is there a reason I am receiving this friendly
> greeter more than once?
>

Don't worry about it.  I've been a member for many years, and I still
get it periodically.  Sometimes it happens if I haven't posted for a few
weeks, and sometimes it just seems gratuitous.


-- 
DaveA


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Reading CSV files in Pandas

2013-10-20 Thread Alan Gauld

On 20/10/13 11:30, Matthew Ngaha wrote:

Does pandas do the same thing numpy does?


Pandas is more about analysis of big data volumes rather than complex 
calculations. eg statistical analysis and data mining.


As such it's closer to R than to numpy in its function, so far as I can 
tell. (Although it uses numpy under the covers).


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Passing arguments?

2013-10-20 Thread Jugurtha Hadjar


Hello,

> the data from the user in main.  You must print the name of the product,
> the weight and the cost of shipping in a separate function.

Your code printed that in main.

>  print('Product:', product)
>
>  print('Weight:', weight)


Also, you have an int(input("weight:"))

Weight seldom is an integer.

There's also no need to create three functions 
(calc_weight_[small|medium|large]) that do the exact same thing: i.e 
multiply the ship rate by the weight.



Also, there is overlap in your calculations:

if weight<=10
shiprate = 1.5
...

elif weight >=10
shiprate = 1.45



What if weight = 10 pounds ? Is the shiprate 1.5 or 1.45 ? In other 
words, you have to exclude one. (The second, to get the most money).


if weight<=10
shiprate = 1.5

elif weight>10
shiprate = 1.45



Now for the code:

Why not make one function that does things:

Warning: I'm on Python 2.7, so take into account raw_input() and print() 
differences.


Also, I haven't modified the type of product_weight and let it integer. 
You might want to change that. I haven't sanitized the inputs, neither.


--code starts here--

def calc_shiprate(product_name, product_weight):

# Takes two (2) arguments: "product_name" and "product_weight".
# Returns "amount_to_pay" by applying ship-rates depending on
# "product_weight".


# Following are the ship-rates in $/pound

shiprate_small = 1.5
shiprate_medium = 1.45
shiprate_large  = 1.4


if product_weight <=10:
shiprate = shiprate_small
elif (product_weight > 10) and (product_weight <= 25):
shiprate = shiprate_medium
else:
shiprate = shiprate_large

amount_to_pay = product_weight * shiprate

print "Total to pay for product %s weighing %d pounds is: %d " % 
(product_name, product_weight, amount_to_pay)



product_name = raw_input("Product name: ")
product_weight = int(raw_input("Product weight: "))

calc_shiprate(product_name, product_weight)


--code ends here--



--
~Jugurtha Hadjar,
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Reading CSV files in Pandas

2013-10-20 Thread John Steedman
I have in front of me a copy an (unread, borrowed) copy of "Python for
Data Analysis".  Well, on page 104, there is the start of an answer.

Pandas : has two useful functions: read_csv and read_table
Numpy : see np.loadtxt and np.genfromtxt

There is an example for using the first numpy function:

arr = np.loadtxt ( fileName, delimiter = ','  )

This information from Python for Data Analysis , author: Wes McKinney
published by O'Reilly - a succinct, useful-looking book.





On Sun, Oct 20, 2013 at 7:05 PM, Alan Gauld  wrote:
> On 20/10/13 11:30, Matthew Ngaha wrote:
>>
>> Does pandas do the same thing numpy does?
>
>
> Pandas is more about analysis of big data volumes rather than complex
> calculations. eg statistical analysis and data mining.
>
> As such it's closer to R than to numpy in its function, so far as I can
> tell. (Although it uses numpy under the covers).
>
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.flickr.com/photos/alangauldphotos
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Passing arguments?

2013-10-20 Thread Alan Gauld

On 20/10/13 05:20, Jenny Allar wrote:

I've written the code below the assignment, and I think I have
everything covered in terms of asking the user for the information I
need and somehow calculating costs, but I'm just ridiculously confused
on the order and placement of the functions and components of this
program- specifically the shiprate variable.


Its pretty much fine except that you define shiprate inside the function 
which overwrites the value you pass in. You should define the value 
before you call the function 9which you are doing) but not set it inside 
the function.


Then you only need to define one function which accepts the shiprate as 
an argument.


One little extra is that you could define a default value for the 
parameter to save you sup[plying it in the most common case:


def calc_weight(weight, shiprate=1.5):
total = weight * shiprate

Although the name does not describe what the function does so
a better name is probably calc_cost()


 if weight <= 10:
 shiprate = 1.5
 calc_weight_small(weight, shiprate)


Notice you call calc_weight_small() here


def cacl_weight_small(weight, shiprate):


But you define cacl_weight_small() here.
That won't work so either you did not send us
your real code or you have a bug waiting to bite...

HTH

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Reading CSV files in Pandas

2013-10-20 Thread Albert-Jan Roskam
On Sun, 10/20/13, Mark Lawrence  wrote:

 Subject: Re: [Tutor] Reading CSV files in Pandas
 To: tutor@python.org
 Date: Sunday, October 20, 2013, 1:16 AM
 
 On 19/10/2013 23:40, Alan Gauld
 wrote:
 
 > This is the second time I've seen pandas mentioned
 recedntly I really
 > must go and look it up to find out what it is...
 
 Just started out myself at http://pandas.pydata.org/ and at first glance it 
seems
 quite awesome.

Yeah, I've read the Pandas book and I was amazed too. It's R (as in CRAN R) on 
steroids.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Fwd: Re: Passing arguments?

2013-10-20 Thread Ricardo Aráoz

Sorry, I sent this answer to the OP directly and not to the list.

 Mensaje original 
Asunto: Re: [Tutor] Passing arguments?
Fecha:  Sun, 20 Oct 2013 11:25:52 -0300
De: Ricardo Aráoz 
A:  Jenny Allar 



El 20/10/13 01:20, Jenny Allar escribió:
I've written the code below the assignment, and I think I have 
everything covered in terms of asking the user for the information I 
need and somehow calculating costs, but I'm just ridiculously confused 
on the order and placement of the functions and components of this 
program- specifically the shiprate variable. Thank you in advance for 
any help.




Ok, just a couple of things first.

- Your assignment specifically says 'always use "while loops" to 
validate' but I see no loop at all in your code. You might want to look 
into it.


- What your assignment points to when it says to use "while loops" 
is that you should validate that what the user inputs is a valid number. 
If the user will input something else than a number as the weight then 
when you apply the int() function an exception will be flagged and your 
program will terminate ungracefully. You may validate input using 
"exceptions" and "while loops" (look it up).


- Your functions should do what their name imply, and preferably do only 
one thing. Having a function named calc_weight_large() that also prints 
the shipping cost is not good.


- Your if asks for >= 10 and your elif for <= 10 when the "= 10" case 
was already handled by the first if, that is a mistake. Besides which it 
might be better looking (though this is a matter of personal preference) 
if you ::

if weight > 25
# do something
elif weight > 10
# do something else
else
# do something entirely different

- I would structure the program in the following way ::
def main():
product = in_product()
weight = in_weight()

if weight > 25
total = calc_shipping(1.40, weight)
elif weight > 10
total = calc_shipping(1.45, weight)
else
total = calc_shipping(1.50, weight)
print_data(product, weight, total)


This is my assignment:

Write a program that asks a user for the name of a product that they 
are ordering online and its weight.  The program must calculate the 
cost of shipping the product using the following cost structure.  If 
it weighs less than 10 pounds the cost is $1.50 per pound, if it is 10 
pounds or more and less than 25 pounds then the cost is $1.45 per 
pound.  If the weight is 25 pounds or more the cost is $1.40 per 
pound.  You may get the data from the user in main.  You must print 
the name of the product, the weight and the cost of shipping in a 
separate function.


*_*NOTE: ALWAYS USE "WHILE LOOPS" To Validate***_*

# This program uses an if-else statement

# It asks for the name of a product and the weight of that product.
# It then determines the shipping cost as defined by the weight.
#
# Variable  Type  Purpose
# product   string  hold for name of product
# weight float   hold for weight of product
#

def main ():
product = input("Please enter the name of the product: ")
weight = int(input("Please enter the weight of the product: "))

print('Product:', product)
print('Weight:', weight)

if weight <= 10:
shiprate = 1.5
calc_weight_small(weight, shiprate)
elif weight >= 10 and weight <= 25:
shiprate = 1.45
calc_weight_medium(weight, shiprate)
else:
shiprate = 1.4
calc_weight_large(weight, shiprate)

# Calculate shipping cost for product less than 10 pounds
def cacl_weight_small(weight, shiprate):
shiprate = 1.5
total = weight * shiprate



# Calculate shipping cost for product between 10 and 25 pounds.
def calc_weight_medium(weight, shiprate):
shiprate = 1.45
total = weight * shiprate



# Calculate shipping cost for product over 25 pounds.
#
#This function calculates and prints the total cost
# based on the weight category the product falls into
# VariableType Purpose

#  weight   floatweight of product
#  shipratefloatcost per pound
#  total   floattotal cost to ship product
#
def calc_weight_large(weight, shiprate):
shiprate = 1.4
total = weight * shiprate
print ()
print ("The cost to ship", product, "is:$", format (total, 
 '9,.2f'))


main ()





___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] string list in alphabetical!

2013-10-20 Thread Sammy Cornet
Hello!I'm using python 2.7.5 version and I'm trying to write a program related 
to a file named unsorted_fruits.txt contains a list of 26 fruits, each one with 
a name that
begins with a different letter of the alphabet. My program's goal is to read in 
the fruits from the file unsorted_fruits.txt
and writes them out in alphabetical order to a file named sorted_fruits.txt 
while I'm using while loop

For
this assignment you must incorporate the use of a list, for loop and / or while
loop.so here is what I have on my script:
infile = open('Desktop/unsorted_fruits.docx' ,"r")outfile = 
open('Desktop/sorted_fruits.docx', 'w')
def find():index = 0while index < 26:list < 26list = 
["a", "b", "c", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n" "o", "p", "q", 
"r", "s", "t", "u", "v", "w", "z", "y", "z"]if index[0] == list[0]: 
   infile = list + 1print infileindex += 1
infile.close() outfile.close() 
And here is my output:
Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on 
win32Type "copyright", "credits" or "license()" for more information.>>> 
 RESTART >>> 
Traceback (most recent call last):  File "F:/7.real.py", line 1, in 
infile = open('Desktop/unsorted_fruits.docx' ,"r")IOError: [Errno 2] No such 
file or directory: 'Desktop/unsorted_fruits.docx'>>> 

I'm not sure if I write the program correctly, but I can't get my file wich is 
on my desktop to the program. CAn someone help me please?








  ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] string list in alphabetical!

2013-10-20 Thread Steven D'Aprano
On Sun, Oct 20, 2013 at 07:16:12PM -0500, Sammy Cornet wrote:

> Hello!I'm using python 2.7.5 version and I'm trying to write a program 
> related to a file named unsorted_fruits.txt contains a list of 26 
.^

Here you say the file is called unsorted_fruits.txt


> infile = open('Desktop/unsorted_fruits.docx' ,"r")
^^

Here you try to open a file called unsorted_fruits.docx


And likewise for the file you are writing to.


-- 
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] string list in alphabetical!

2013-10-20 Thread Mark Lawrence

On 21/10/2013 01:16, Sammy Cornet wrote:

Hello!

I'm using python 2.7.5 version and I'm trying to write a program related
to a file named unsorted_fruits.txt contains a list of 26 fruits, each
one with a name that begins with a different letter of the alphabet. My
program's goal is to read in the fruits from the file
unsorted_fruits.txt and writes them out in alphabetical order to a file
named sorted_fruits.txt while I'm using while loop

For this assignment you must incorporate the use of a list, for loop and
/ or while loop.

so here is what I have on my script:


infile = open('Desktop/unsorted_fruits.docx' ,"r")

outfile = open('Desktop/sorted_fruits.docx', 'w')


def find():

 index = 0

 while index < 26:

 list < 26

 list = ["a", "b", "c", "e", "f", "g", "h", "i", "j", "k", "l",
"m", "n" "o", "p", "q", "r", "s", "t", "u", "v", "w", "z", "y", "z"]

 if index[0] == list[0]:

 infile = list + 1

 print infile

 index += 1

 infile.close()

 outfile.close()


And here is my output:

Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit
(Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
 >>>  RESTART

 >>>

Traceback (most recent call last):
   File "F:/7.real.py", line 1, in 
 infile = open('Desktop/unsorted_fruits.docx' ,"r")
IOError: [Errno 2] No such file or directory: 'Desktop/unsorted_fruits.docx'
 >>>



Once you have fixed the file name error which Steven has already pointed 
out, do you intend to call the function find that you have defined?  If 
yes can I suggest that you use paper and pencil to work out what it 
does, or more accurately doesn't do, as it's strewn with errors.


--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Reading CSV files in Pandas

2013-10-20 Thread Sivaram Neelakantan
On Sun, Oct 20 2013,Mark Lawrence wrote:

> On 19/10/2013 23:40, Alan Gauld wrote:
>
>> This is the second time I've seen pandas mentioned recedntly I really
>> must go and look it up to find out what it is...
>
> Just started out myself at http://pandas.pydata.org/ and at first
> glance it seems quite awesome.

The data handling framework is very good; it cuts out large swathes of
code from a normal procedural coding POV.  That is, instead of lists,
tuples etc. you work with a conceptual dataframe, like R.

 sivaram
 -- 

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Reading CSV files in Pandas

2013-10-20 Thread Sivaram Neelakantan
On Sat, Oct 19 2013,Manish Tripathi wrote:

> I am trying to import a csv file in Pandas but it throws an error. The
> format of the data when opened in notepad++ is as follows with first row
> being column names:


you could try the following newsgroup or mailing list for more
specialised help.

 gmane.org:gmane.comp.python.pydata

[snipped 82 lines]



 sivaram
 -- 

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor