Problem in defining multidimensional array matrix and regression
Hi, All, I have 6 variables in CSV file. One is rainfall (dependent, at y-axis) and others are predictors (at x). I want to do multiple regression and create a correlation matrix between rainfall (y) and predictors (x; n1=5). Thus I want to read rainfall as a separate variable and others in separate columns, so I can apply the algo. However, I am not able to make a proper matrix for them. Here are my data and codes? Please suggest me for the same. I am new to Python. RF P1 P2 P3 P4 P5 120.235 0.234 -0.012 0.145 21.023 0.233 200.14 0.512 -0.021 0.214 22.21 0.332 185.362 0.147 -0.32 0.136 24.65 0.423 201.895 0.002 -0.12 0.217 30.25 0.325 165.235 0.256 0.001 0.2231.245 0.552 198.236 0.012 -0.362 0.215 32.25 0.333 350.263 0.98-0.85 0.321 38.412 0.411 145.25 0.046 -0.36 0.147 39.256 0.872 198.654 0.65-0.45 0.224 40.235 0.652 245.214 0.47-0.325 0.311 26.356 0.632 214.02 0.18-0.012 0.242 22.01 0.745 147.256 0.652 -0.785 0.311 18.256 0.924 import numpy as np import statsmodels as sm import statsmodels.formula as smf import csv with open("pcp1.csv", "r") as csvfile: readCSV=csv.reader(csvfile) rainfall = [] csvFileList = [] for row in readCSV: Rain = row[0] rainfall.append(Rain) if len (row) !=0: csvFileList = csvFileList + [row] print(csvFileList) print(rainfall) Please suggest me guys Thanks -- https://mail.python.org/mailman/listinfo/python-list
Re: Problem in defining multidimensional array matrix and regression
shalu.ash...@gmail.com wrote: > Hi, All, > > I have 6 variables in CSV file. One is rainfall (dependent, at y-axis) and > others are predictors (at x). I want to do multiple regression and create > a correlation matrix between rainfall (y) and predictors (x; n1=5). Thus I > want to read rainfall as a separate variable and others in separate > columns, so I can apply the algo. However, I am not able to make a proper > matrix for them. > > Here are my data and codes? > Please suggest me for the same. > I am new to Python. > > RFP1 P2 P3 P4 P5 > 120.235 0.234 -0.012 0.145 21.023 0.233 > 200.140.512 -0.021 0.214 22.21 0.332 > 185.362 0.147 -0.32 0.136 24.65 0.423 > 201.895 0.002 -0.12 0.217 30.25 0.325 > 165.235 0.256 0.001 0.2231.245 0.552 > 198.236 0.012 -0.362 0.215 32.25 0.333 > 350.263 0.98-0.85 0.321 38.412 0.411 > 145.250.046 -0.36 0.147 39.256 0.872 > 198.654 0.65-0.45 0.224 40.235 0.652 > 245.214 0.47-0.325 0.311 26.356 0.632 > 214.020.18-0.012 0.242 22.01 0.745 > 147.256 0.652 -0.785 0.311 18.256 0.924 > > import numpy as np > import statsmodels as sm > import statsmodels.formula as smf > import csv > > with open("pcp1.csv", "r") as csvfile: > readCSV=csv.reader(csvfile) > > rainfall = [] > csvFileList = [] > > for row in readCSV: > Rain = row[0] > rainfall.append(Rain) > > if len (row) !=0: > csvFileList = csvFileList + [row] > > print(csvFileList) > print(rainfall) You are not the first to read tabular data from a file; therefore numpy (and pandas) offer highlevel function to do just that. Once you have the complete table extracting a specific column is easy. For instance: $ cat rainfall.txt RF P1 P2 P3 P4 P5 120.235 0.234 -0.012 0.145 21.023 0.233 200.14 0.512 -0.021 0.214 22.21 0.332 185.362 0.147 -0.32 0.136 24.65 0.423 201.895 0.002 -0.12 0.217 30.25 0.325 165.235 0.256 0.001 0.2231.245 0.552 198.236 0.012 -0.362 0.215 32.25 0.333 350.263 0.98-0.85 0.321 38.412 0.411 145.25 0.046 -0.36 0.147 39.256 0.872 198.654 0.65-0.45 0.224 40.235 0.652 245.214 0.47-0.325 0.311 26.356 0.632 214.02 0.18-0.012 0.242 22.01 0.745 147.256 0.652 -0.785 0.311 18.256 0.924 $ python3 Python 3.4.3 (default, Nov 17 2016, 01:08:31) [GCC 4.8.4] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import numpy >>> rf = numpy.genfromtxt("rainfall.txt", names=True) >>> rf["RF"] array([ 120.235, 200.14 , 185.362, 201.895, 165.235, 198.236, 350.263, 145.25 , 198.654, 245.214, 214.02 , 147.256]) >>> rf["P3"] array([ 0.145, 0.214, 0.136, 0.217, 0.22 , 0.215, 0.321, 0.147, 0.224, 0.311, 0.242, 0.311]) -- https://mail.python.org/mailman/listinfo/python-list
Re: Problem in defining multidimensional array matrix and regression
Hello Peter, Many thanks for your suggestion. Now I am using Pandas & I already did that but now I need to make a multi-dimensional array for reading all variables (5 in this case) at one x-axis, so I can perform multiple regression analysis. I am not getting how to bring all variables at one axis (e.g. at x-axis)? Thanks Vishal On Sunday, 19 November 2017 22:32:06 UTC+5:30, Peter Otten wrote: > shalu.ash...@gmail.com wrote: > > > Hi, All, > > > > I have 6 variables in CSV file. One is rainfall (dependent, at y-axis) and > > others are predictors (at x). I want to do multiple regression and create > > a correlation matrix between rainfall (y) and predictors (x; n1=5). Thus I > > want to read rainfall as a separate variable and others in separate > > columns, so I can apply the algo. However, I am not able to make a proper > > matrix for them. > > > > Here are my data and codes? > > Please suggest me for the same. > > I am new to Python. > > > > RF P1 P2 P3 P4 P5 > > 120.235 0.234 -0.012 0.145 21.023 0.233 > > 200.14 0.512 -0.021 0.214 22.21 0.332 > > 185.362 0.147 -0.32 0.136 24.65 0.423 > > 201.895 0.002 -0.12 0.217 30.25 0.325 > > 165.235 0.256 0.001 0.2231.245 0.552 > > 198.236 0.012 -0.362 0.215 32.25 0.333 > > 350.263 0.98-0.85 0.321 38.412 0.411 > > 145.25 0.046 -0.36 0.147 39.256 0.872 > > 198.654 0.65-0.45 0.224 40.235 0.652 > > 245.214 0.47-0.325 0.311 26.356 0.632 > > 214.02 0.18-0.012 0.242 22.01 0.745 > > 147.256 0.652 -0.785 0.311 18.256 0.924 > > > > import numpy as np > > import statsmodels as sm > > import statsmodels.formula as smf > > import csv > > > > with open("pcp1.csv", "r") as csvfile: > > readCSV=csv.reader(csvfile) > > > > rainfall = [] > > csvFileList = [] > > > > for row in readCSV: > > Rain = row[0] > > rainfall.append(Rain) > > > > if len (row) !=0: > > csvFileList = csvFileList + [row] > > > > print(csvFileList) > > print(rainfall) > > You are not the first to read tabular data from a file; therefore numpy (and > pandas) offer highlevel function to do just that. Once you have the complete > table extracting a specific column is easy. For instance: > > $ cat rainfall.txt > RF P1 P2 P3 P4 P5 > 120.235 0.234 -0.012 0.145 21.023 0.233 > 200.14 0.512 -0.021 0.214 22.21 0.332 > 185.362 0.147 -0.32 0.136 24.65 0.423 > 201.895 0.002 -0.12 0.217 30.25 0.325 > 165.235 0.256 0.001 0.2231.245 0.552 > 198.236 0.012 -0.362 0.215 32.25 0.333 > 350.263 0.98-0.85 0.321 38.412 0.411 > 145.25 0.046 -0.36 0.147 39.256 0.872 > 198.654 0.65-0.45 0.224 40.235 0.652 > 245.214 0.47-0.325 0.311 26.356 0.632 > 214.02 0.18-0.012 0.242 22.01 0.745 > 147.256 0.652 -0.785 0.311 18.256 0.924 > $ python3 > Python 3.4.3 (default, Nov 17 2016, 01:08:31) > [GCC 4.8.4] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> import numpy > >>> rf = numpy.genfromtxt("rainfall.txt", names=True) > >>> rf["RF"] > array([ 120.235, 200.14 , 185.362, 201.895, 165.235, 198.236, > 350.263, 145.25 , 198.654, 245.214, 214.02 , 147.256]) > >>> rf["P3"] > array([ 0.145, 0.214, 0.136, 0.217, 0.22 , 0.215, 0.321, 0.147, > 0.224, 0.311, 0.242, 0.311]) -- https://mail.python.org/mailman/listinfo/python-list
Student can't get if elif final statement to print for discussion post for python
I've tried several variations but haven't been able to figure out why my final if elif statement won't print. I tried using return, I tried using 1's and 0's rather than yes and no. Not sure what the issue is. Please, help. #This function will print how many yes answers the user has and a message def correctAnswers(job, house, yard, time): if correctAnswers == 'yes': print ("Congratulations! You should get a puppy!") else: return "I'm sorry, you shouldn't get a puppy." -- https://mail.python.org/mailman/listinfo/python-list
Re: Problem in defining multidimensional array matrix and regression
shalu.ash...@gmail.com writes: > I already did that Peter's suggestion was quite different from the code you first presented. So, I am not understanding what you mean by “I already did that”. Can you: * Reply with your responses interleaved with the quote text https://en.wikipedia.org/wiki/Posting_style#Interleaved_style>, so that your message reads like a proper discussion. (This message is an example of that.) * Show the code you wrote where you “already did that”, and say what happened different from what you expected. > but now I need to make a multi-dimensional array for reading all > variables (5 in this case) at one x-axis From what I can tell, that's exactly what Peter's example shows: you get a multi-dimensional array, with all the named variables “RF”, “P1”, “P2”, and so on, addressible by name. That should allow you to directly operate on that multi-dimensional array by naming the variables. > I am not getting how to bring all variables at one axis (e.g. at > x-axis)? I don't understand what you mean by that; all the variables are present in the array. -- \ “I don't like country music, but I don't mean to denigrate | `\ those who do. And for the people who like country music, | _o__)denigrate means ‘put down’.” —Bob Newhart | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list
Is there something like head() and str() of R in python?
Hi, R has the functions head() and str() to show the brief content of an object. Is there something similar in python for this purpose? For example, I want to inspect the content of the variable "train". What is the best way to do so? Thanks. $ cat demo.py from __future__ import division, print_function, absolute_import import tflearn from tflearn.data_utils import to_categorical, pad_sequences from tflearn.datasets import imdb # IMDB Dataset loading train, test, _ = imdb.load_data(path='imdb.pkl', n_words=1, valid_portion=0.1) # https://raw.githubusercontent.com/llSourcell/How_to_do_Sentiment_Analysis/master/demo.py -- Regards, Peng -- https://mail.python.org/mailman/listinfo/python-list
Re: Student can't get if elif final statement to print for discussion post for python
Cheri Castro writes: > I've tried several variations but haven't been able to figure out why > my final if elif statement won't print. The code you presented here does not have any ‘elif’ clause. Did you mean to show different code? > I tried using return, I tried using 1's and 0's rather than yes and > no. Not sure what the issue is. Please, help. Your questions are welcome here, but you may also be interested in http://mail.python.org/mailman/listinfo/tutor> the “tutor” discussion forum especially for Python beginners. > #This function will print how many yes answers the user has and a message > def correctAnswers(job, house, yard, time): > if correctAnswers == 'yes': > print ("Congratulations! You should get a puppy!") > else: > return "I'm sorry, you shouldn't get a puppy." The ‘if’ clause tests the value of ‘correctAnswers’. Where do you expect that value to come from? Nothing in the function ever sets a value to that name. On the other hand, the function never makes use of ‘job’, ‘house’, ‘yard’, or ‘time’. Why are those parameters to the function? -- \ “How wonderful that we have met with a paradox. Now we have | `\some hope of making progress.” —Niels Bohr | _o__) | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list
Re: Student can't get if elif final statement to print for discussion post for python
On 2017-11-19 19:03, Ben Finney wrote: Cheri Castro writes: I've tried several variations but haven't been able to figure out why my final if elif statement won't print. The code you presented here does not have any ‘elif’ clause. Did you mean to show different code? I tried using return, I tried using 1's and 0's rather than yes and no. Not sure what the issue is. Please, help. Your questions are welcome here, but you may also be interested in http://mail.python.org/mailman/listinfo/tutor> the “tutor” discussion forum especially for Python beginners. #This function will print how many yes answers the user has and a message def correctAnswers(job, house, yard, time): if correctAnswers == 'yes': print ("Congratulations! You should get a puppy!") else: return "I'm sorry, you shouldn't get a puppy." The ‘if’ clause tests the value of ‘correctAnswers’. Where do you expect that value to come from? Nothing in the function ever sets a value to that name. On the other hand, the function never makes use of ‘job’, ‘house’, ‘yard’, or ‘time’. Why are those parameters to the function? The function itself is called 'correctAnswers', and a function is never equal to a string. -- https://mail.python.org/mailman/listinfo/python-list
Re: "help( pi )"
Cameron Simpson wrote: Unless one had a misfortune and wanted another docstring. Good point. I guess having differing docstrings should make otherwise equal objects ineligible for merging. mod1.py: MAX_BUFSIZE = 8192 MAX_BUFSIZE.__doc__ = 'Size of the hardware buffer used for I/O on this device.' mod2.py DEFAULT_CACHESIZE = 8192 DEFAULT_CACHESIZE.__doc__ = 'Convenient size for the foo cache, not to big or too small.' I think setting the docstring of an existing immutable object would have to be disallowed -- you need to create a new object if you want it to have a distinct docstring, e.g. MAX_BUFSIZE = int(8192, __doc__ = 'Size of the hardware buffer used for I/O on this device.') -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Problem in defining multidimensional array matrix and regression
On 19/11/17 18:55, shalu.ash...@gmail.com wrote: > Hello Peter, > > Many thanks for your suggestion. > Now I am using Pandas & > I already did that but now I need to make a multi-dimensional array for > reading all variables (5 in this case) at one x-axis, so I can perform > multiple regression analysis. > > I am not getting how to bring all variables at one axis (e.g. at x-axis)? Pandas is great at this: index a single row of a DataFrame with your favourite selector from http://pandas.pydata.org/pandas-docs/stable/indexing.html (or just loop over the DataFrame's .iterrows) If you want a multi-dimensional array with all the data, numpy.loadtxt can do that for you. > > Thanks > Vishal > > On Sunday, 19 November 2017 22:32:06 UTC+5:30, Peter Otten wrote: >> shalu.ash...@gmail.com wrote: >> >>> Hi, All, >>> >>> I have 6 variables in CSV file. One is rainfall (dependent, at y-axis) and >>> others are predictors (at x). I want to do multiple regression and create >>> a correlation matrix between rainfall (y) and predictors (x; n1=5). Thus I >>> want to read rainfall as a separate variable and others in separate >>> columns, so I can apply the algo. However, I am not able to make a proper >>> matrix for them. >>> >>> Here are my data and codes? >>> Please suggest me for the same. >>> I am new to Python. >>> >>> RF P1 P2 P3 P4 P5 >>> 120.235 0.234 -0.012 0.145 21.023 0.233 >>> 200.14 0.512 -0.021 0.214 22.21 0.332 >>> 185.362 0.147 -0.32 0.136 24.65 0.423 >>> 201.895 0.002 -0.12 0.217 30.25 0.325 >>> 165.235 0.256 0.001 0.2231.245 0.552 >>> 198.236 0.012 -0.362 0.215 32.25 0.333 >>> 350.263 0.98-0.85 0.321 38.412 0.411 >>> 145.25 0.046 -0.36 0.147 39.256 0.872 >>> 198.654 0.65-0.45 0.224 40.235 0.652 >>> 245.214 0.47-0.325 0.311 26.356 0.632 >>> 214.02 0.18-0.012 0.242 22.01 0.745 >>> 147.256 0.652 -0.785 0.311 18.256 0.924 >>> >>> import numpy as np >>> import statsmodels as sm >>> import statsmodels.formula as smf >>> import csv >>> >>> with open("pcp1.csv", "r") as csvfile: >>> readCSV=csv.reader(csvfile) >>> >>> rainfall = [] >>> csvFileList = [] >>> >>> for row in readCSV: >>> Rain = row[0] >>> rainfall.append(Rain) >>> >>> if len (row) !=0: >>> csvFileList = csvFileList + [row] >>> >>> print(csvFileList) >>> print(rainfall) >> >> You are not the first to read tabular data from a file; therefore numpy (and >> pandas) offer highlevel function to do just that. Once you have the complete >> table extracting a specific column is easy. For instance: >> >> $ cat rainfall.txt >> RF P1 P2 P3 P4 P5 >> 120.235 0.234 -0.012 0.145 21.023 0.233 >> 200.14 0.512 -0.021 0.214 22.21 0.332 >> 185.362 0.147 -0.32 0.136 24.65 0.423 >> 201.895 0.002 -0.12 0.217 30.25 0.325 >> 165.235 0.256 0.001 0.2231.245 0.552 >> 198.236 0.012 -0.362 0.215 32.25 0.333 >> 350.263 0.98-0.85 0.321 38.412 0.411 >> 145.25 0.046 -0.36 0.147 39.256 0.872 >> 198.654 0.65-0.45 0.224 40.235 0.652 >> 245.214 0.47-0.325 0.311 26.356 0.632 >> 214.02 0.18-0.012 0.242 22.01 0.745 >> 147.256 0.652 -0.785 0.311 18.256 0.924 >> $ python3 >> Python 3.4.3 (default, Nov 17 2016, 01:08:31) >> [GCC 4.8.4] on linux >> Type "help", "copyright", "credits" or "license" for more information. > import numpy > rf = numpy.genfromtxt("rainfall.txt", names=True) > rf["RF"] >> array([ 120.235, 200.14 , 185.362, 201.895, 165.235, 198.236, >> 350.263, 145.25 , 198.654, 245.214, 214.02 , 147.256]) > rf["P3"] >> array([ 0.145, 0.214, 0.136, 0.217, 0.22 , 0.215, 0.321, 0.147, >> 0.224, 0.311, 0.242, 0.311]) > -- https://mail.python.org/mailman/listinfo/python-list
Re: Student can't get if elif final statement to print for discussion post for python
On 11/19/17 1:10 PM, Cheri Castro wrote: I've tried several variations but haven't been able to figure out why my final if elif statement won't print. I tried using return, I tried using 1's and 0's rather than yes and no. Not sure what the issue is. Please, help. #This function will print how many yes answers the user has and a message def correctAnswers(job, house, yard, time): if correctAnswers == 'yes': print ("Congratulations! You should get a puppy!") else: return "I'm sorry, you shouldn't get a puppy." Why does one path print and the other return, those are different actions. -- Richard Damon -- https://mail.python.org/mailman/listinfo/python-list
Re: Test - please ignore (again)
> Another test of SpamBayes in comp.lang.python -> python-list gateway. Still leaning on the submit button to see what gate_news thinks... Skip -- https://mail.python.org/mailman/listinfo/python-list
How to Generate dynamic HTML Report using Python
Hi All , I am new to python . I am trying to generate Dynamic HTML report using Pyhton based on number of rows selected from query .Do any one can suggest some thing for it. Thanks, Mradul -- https://mail.python.org/mailman/listinfo/python-list
Re: How to Generate dynamic HTML Report using Python
On 11/19/17 8:40 PM, Stefan Ram wrote: mradul dhakad writes: I am new to python . I am trying to generate Dynamic HTML report using Pyhton based on number of rows selected from query .Do any one can suggest some thing for it. main.py import sqlite3 conn = sqlite3.connect( ':memory:' ) c = conn.cursor() c.execute( "CREATE TABLE T ( A TEXT )" ) c.execute( "INSERT INTO T ( A ) VALUES ( '1' ), ( '2' )" ) conn.commit() c.execute( "SELECT * FROM T WHERE A = '1'" ) number_of_rows_selected_from_query = len( c.fetchall() ) conn.close() del c del conn del sqlite3 I'm curious what superstition compels you to delete these names? There's no need to. Also, why set headers that prevent the Python-List mailing list from archiving your messages? --Ned. def HTML( x ): return f''' http://www.w3.org/1999/xhtml"; lang="de" xml:lang="de"> Number Of Rows Selected From Query Number Of Rows Selected From Query The number of rows selected from query is {x}.''' print( HTML( number_of_rows_selected_from_query )) transcript http://www.w3.org/1999/xhtml"; lang="de" xml:lang="de"> Number Of Rows Selected From Query Number Of Rows Selected From Query The number of rows selected from query is 1. -- https://mail.python.org/mailman/listinfo/python-list
Re: Problem in defining multidimensional array matrix and regression
On Sun, 19 Nov 2017, shalu.ash...@gmail.com wrote: > Hi, All, > >I have 6 variables in CSV file. One is rainfall (dependent, at >y-axis) and others are predictors (at x). I want to do multiple >regression and create a correlation matrix between rainfall (y) and >predictors (x; n1=5). Thus I want to read rainfall as a separate >variable and others in separate columns, so I can apply the algo. However, I am >not able to make a proper matrix for them. > >Here are my data and codes? >Please suggest me for the same. >I am new to Python. > >RF P1 P2 P3 P4 P5 >120.2350.234 -0.012 0.145 21.023 0.233 >200.14 0.512 -0.021 0.214 22.21 0.332 >185.3620.147 -0.32 0.136 24.65 0.423 >201.8950.002 -0.12 0.217 30.25 0.325 >165.2350.256 0.001 0.2231.245 0.552 >198.2360.012 -0.362 0.215 32.25 0.333 >350.2630.98-0.85 0.321 38.412 0.411 >145.25 0.046 -0.36 0.147 39.256 0.872 >198.6540.65-0.45 0.224 40.235 0.652 >245.2140.47-0.325 0.311 26.356 0.632 >214.02 0.18-0.012 0.242 22.01 0.745 >147.2560.652 -0.785 0.311 18.256 0.924 > >import numpy as np >import statsmodels as sm >import statsmodels.formula as smf >import csv > >with open("pcp1.csv", "r") as csvfile: >readCSV=csv.reader(csvfile) > >rainfall = [] >csvFileList = [] > >for row in readCSV: >Rain = row[0] >rainfall.append(Rain) > >if len (row) !=0: >csvFileList = csvFileList + [row] > >print(csvFileList) >print(rainfall) > >Please suggest me guys >Thanks > There seems to be a conceptual disconnect here. Do you happen to know what the letters C,S,V stand for in CSV file? Because I don't see any C's in your data, and I don't see anything in your code to use anything other than C to S your V's. I'm thinking that is the first place you should look. You could either modify your data file (with a nice global replace/change) or you could give a different value to one of the default parameters to the functions you use to open the file. Roger Christman Pennsylvania State University -- https://mail.python.org/mailman/listinfo/python-list
Re: How to Generate dynamic HTML Report using Python
I have a piece of code (module) implementing dynamic html page generation. What it simply does is writes all the html content (tags + data) to a file, and the file is save with a (.html) extension. Served my purpose. Not really sure is this is something you are looking for. You can view the code here: https://github.com/kryptxy/torrench/blob/master/torrench/modules/tpb_details.py Hope this helps. Original Message On 20 Nov 2017, 6:46 AM, mradul dhakad wrote: > Hi All , > > I am new to python . I am trying to generate Dynamic HTML report using > Pyhton based on number of rows selected from query .Do any one can suggest > some thing for it. > > Thanks, > Mradul > -- > https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list