<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Ask Ghassem - Recent activity in Python</title>
<link>https://ask.ghassem.com/activity/programming/python</link>
<description>Powered by Question2Answer</description>
<item>
<title>Which code has best runtime and why?(the one commented or the other one)</title>
<link>https://ask.ghassem.com/1027/which-code-has-best-runtime-and-why-the-one-commented-the-other</link>
<description># for key, value in dict.items():&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;# &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if value &amp;gt;= long:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;# &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;long = value&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;# &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;long_name = key&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;# &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if value &amp;lt; short:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;# &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;short = value&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;# &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;short_name = key&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;long = max(dict.values())&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;long_name = max(dict, key=dict.get)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;short = min(dict.values())&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;short_name = min(dict, key=dict.get)</description>
<category>Python</category>
<guid isPermaLink="true">https://ask.ghassem.com/1027/which-code-has-best-runtime-and-why-the-one-commented-the-other</guid>
<pubDate>Fri, 02 Sep 2022 14:39:49 +0000</pubDate>
</item>
<item>
<title>Answered: how to output f1-score instead of accuracy</title>
<link>https://ask.ghassem.com/1019/how-to-output-f1-score-instead-of-accuracy?show=1020#a1020</link>
<description>&lt;pre class=&quot;prettyprint lang-python&quot; data-pbcklang=&quot;python&quot; data-pbcktabsize=&quot;4&quot;&gt;
&amp;nbsp;&lt;/pre&gt;

&lt;pre&gt;
from sklearn.metrics import f1_score
&lt;code&gt;f1_score(data_test,target_test)&lt;/code&gt;&lt;/pre&gt;


</description>
<category>Python</category>
<guid isPermaLink="true">https://ask.ghassem.com/1019/how-to-output-f1-score-instead-of-accuracy?show=1020#a1020</guid>
<pubDate>Sat, 02 Apr 2022 14:32:22 +0000</pubDate>
</item>
<item>
<title>I cannot get this code to work. please help.</title>
<link>https://ask.ghassem.com/1018/i-cannot-get-this-code-to-work-please-help</link>
<description>&lt;p&gt;from keras.models import Sequential&amp;nbsp;&lt;br&gt;
from keras.layers import Dense&amp;nbsp;&lt;br&gt;
from keras.layers import LSTM&amp;nbsp;&lt;br&gt;
from sklearn.model_selection import train_test_split&lt;/p&gt;

&lt;p&gt;model = Sequential()&amp;nbsp;&lt;br&gt;
model.add(LSTM( 10, input_shape=(1, 1)))&amp;nbsp;&lt;br&gt;
model.add(Dense(1, activation=&quot;linear&quot;))&amp;nbsp;&lt;br&gt;
model.compile(loss=&quot;mse&quot;, optimizer=&quot;adam&quot;)&lt;/p&gt;

&lt;p&gt;X, y = get_data()&lt;/p&gt;

&lt;p&gt;X_train, X_test, y_train, y_test = train_test_split(x, y, test_size=0.2, random_state=1)&lt;br&gt;
X_train_2, X_val, y_train_2, y_val = train_test_split(X_train, y_train, test_size=0.25, random_state=1)&lt;/p&gt;

&lt;p&gt;model.fit(X_train, y_train, epochs=800, validation_data=(X_val, y_val), shuffle=False)&lt;/p&gt;
html, body, table, thead, input, textarea, select {color: #bab5ab!important; background: #35393b;} input[type=&quot;text&quot;], textarea, select {color: #bab5ab!important; background: #35393b;} [data-darksite-inline-background-image-gradient] {background: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5))!important; -webkit-background-size: cover!important; -moz-background-size: cover!important; -o-background-size: cover!important; background-size: cover!important;} [data-darksite-force-inline-background] * {background-color: rgba(0,0,0,0.7)!important;} [data-darksite-inline-background] {background-color: rgba(0,0,0,0.7)!important;} [data-darksite-inline-color] {color: #fff!important;} [data-darksite-inline-background-image] {background-image: linear-gradient(rgba(0,0,0,0.3), rgba(0,0,0,0.3))!important}
</description>
<category>Python</category>
<guid isPermaLink="true">https://ask.ghassem.com/1018/i-cannot-get-this-code-to-work-please-help</guid>
<pubDate>Mon, 21 Mar 2022 05:59:53 +0000</pubDate>
</item>
<item>
<title>How to print confusion matrix if I am using stratifiedkfold method?</title>
<link>https://ask.ghassem.com/894/how-to-print-confusion-matrix-using-stratifiedkfold-method</link>
<description></description>
<category>Python</category>
<guid isPermaLink="true">https://ask.ghassem.com/894/how-to-print-confusion-matrix-using-stratifiedkfold-method</guid>
<pubDate>Thu, 06 Aug 2020 21:41:19 +0000</pubDate>
</item>
<item>
<title>I am facing the error after importing torch module in python. How can I solve it? The error link is given below</title>
<link>https://ask.ghassem.com/893/facing-error-after-importing-torch-module-python-solve-error</link>
<description>&lt;p&gt;&lt;img alt=&quot;&quot; src=&quot;https://ibb.co/MgXvrkL&quot;&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://ibb.co/MgXvrkL&quot;&gt;https://ibb.co/MgXvrkL&lt;/a&gt;&lt;/p&gt;</description>
<category>Python</category>
<guid isPermaLink="true">https://ask.ghassem.com/893/facing-error-after-importing-torch-module-python-solve-error</guid>
<pubDate>Fri, 31 Jul 2020 14:56:42 +0000</pubDate>
</item>
<item>
<title>Edited: Suggestion For Model</title>
<link>https://ask.ghassem.com/890/suggestion-for-model?show=890#q890</link>
<description></description>
<category>Python</category>
<guid isPermaLink="true">https://ask.ghassem.com/890/suggestion-for-model?show=890#q890</guid>
<pubDate>Thu, 30 Jul 2020 22:11:03 +0000</pubDate>
</item>
<item>
<title>How to split into train and test using PKL file?</title>
<link>https://ask.ghassem.com/892/how-to-split-into-train-and-test-using-pkl-file</link>
<description></description>
<category>Python</category>
<guid isPermaLink="true">https://ask.ghassem.com/892/how-to-split-into-train-and-test-using-pkl-file</guid>
<pubDate>Thu, 30 Jul 2020 22:08:47 +0000</pubDate>
</item>
<item>
<title>Answered: What are some best features of Python3 in comparison to Python2?</title>
<link>https://ask.ghassem.com/636/what-are-some-best-features-of-python3-in-comparison-python2?show=637#a637</link>
<description>&lt;p&gt;There is a list of great features many do not use yet. Here is the list of some of them:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;f-strings (3.6+)&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Pathlib (3.4+)&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Type hinting (3.5+)&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Enumerations (3.4+)&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Built-in LRU cache (3.2+)&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Extended iterable unpacking (3.0+)&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Data classes (3.7+)&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Implicit namespace packages (3.3+)&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://datawhatnow.com/things-you-are-probably-not-using-in-python-3-but-should&quot;&gt;This article&lt;/a&gt;&lt;/strong&gt; shows some examples, and you can take the notebook for your test from &lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/Weenkus/DataWhatNow-Codes/blob/master/things_you_are_probably_not_using_in_python_3_but_should/python%203%20examples.ipynb&quot;&gt;this GitHub page&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;</description>
<category>Python</category>
<guid isPermaLink="true">https://ask.ghassem.com/636/what-are-some-best-features-of-python3-in-comparison-python2?show=637#a637</guid>
<pubDate>Mon, 20 May 2019 16:19:34 +0000</pubDate>
</item>
<item>
<title>Answered: What are the best resources for studying Python?</title>
<link>https://ask.ghassem.com/5/what-are-the-best-resources-for-studying-python?show=634#a634</link>
<description>&lt;p&gt;Hey! There are a ton of good websites that provide both in-depth theoretical knowledge on python, as well as easy to follow practical projects. Here are just a few sites this that:&lt;/p&gt;

&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.learnpython.org/&quot;&gt;https://www.learnpython.org/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.codecademy.com/learn/learn-python&quot;&gt;https://www.codecademy.com/learn/learn-python&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.codecademy.com/learn/learn-python&quot;&gt;https://www.codecademy.com/learn/learn-python&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Feel free to check out any of these sites!&amp;nbsp;&lt;/p&gt;

&lt;p&gt;Hope this helps.&lt;/p&gt;</description>
<category>Python</category>
<guid isPermaLink="true">https://ask.ghassem.com/5/what-are-the-best-resources-for-studying-python?show=634#a634</guid>
<pubDate>Mon, 20 May 2019 11:57:40 +0000</pubDate>
</item>
<item>
<title>Commented: Who can write a recursive Python program for Fibonacci sequence 0,1,1,2,3,5,8,...?</title>
<link>https://ask.ghassem.com/583/who-can-write-recursive-python-program-fibonacci-sequence?show=594#c594</link>
<description>You should correct your code as follows:&lt;br /&gt;
&lt;br /&gt;
sum = fibonacci(n-1) + fibonacci(n-2)</description>
<category>Python</category>
<guid isPermaLink="true">https://ask.ghassem.com/583/who-can-write-recursive-python-program-fibonacci-sequence?show=594#c594</guid>
<pubDate>Fri, 22 Mar 2019 19:39:16 +0000</pubDate>
</item>
<item>
<title>Answered: How do I create comments in my code?</title>
<link>https://ask.ghassem.com/467/how-do-i-create-comments-in-my-code?show=502#a502</link>
<description>&lt;p&gt;Just use # to add comments in your code. Below is an example of how you can add the comments in python&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-python&quot; data-pbcklang=&quot;python&quot; data-pbcktabsize=&quot;4&quot;&gt;
import numpy as np
# importing numpy library&lt;/pre&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description>
<category>Python</category>
<guid isPermaLink="true">https://ask.ghassem.com/467/how-do-i-create-comments-in-my-code?show=502#a502</guid>
<pubDate>Fri, 02 Nov 2018 14:27:35 +0000</pubDate>
</item>
<item>
<title>Reshown: If s=&#039;Sammy&#039; what is the output of s[2:]?</title>
<link>https://ask.ghassem.com/469/if-s-sammy-what-is-the-output-of-s-2?show=469#q469</link>
<description></description>
<category>Python</category>
<guid isPermaLink="true">https://ask.ghassem.com/469/if-s-sammy-what-is-the-output-of-s-2?show=469#q469</guid>
<pubDate>Wed, 31 Oct 2018 17:48:36 +0000</pubDate>
</item>
<item>
<title>Retagged: Can you share with us how to download ipynb file as pdf through latex?</title>
<link>https://ask.ghassem.com/250/can-you-share-with-how-download-ipynb-file-pdf-through-latex?show=250#q250</link>
<description></description>
<category>Python</category>
<guid isPermaLink="true">https://ask.ghassem.com/250/can-you-share-with-how-download-ipynb-file-pdf-through-latex?show=250#q250</guid>
<pubDate>Wed, 31 Oct 2018 17:43:24 +0000</pubDate>
</item>
<item>
<title>Retagged: How to force Jupyter Notebook to print all the variables in each cell, not just the last one?</title>
<link>https://ask.ghassem.com/316/force-jupyter-notebook-print-variables-each-cell-just-last?show=316#q316</link>
<description></description>
<category>Python</category>
<guid isPermaLink="true">https://ask.ghassem.com/316/force-jupyter-notebook-print-variables-each-cell-just-last?show=316#q316</guid>
<pubDate>Wed, 31 Oct 2018 17:43:02 +0000</pubDate>
</item>
<item>
<title>Answered: What are Decorators?</title>
<link>https://ask.ghassem.com/472/what-are-decorators?show=473#a473</link>
<description>Technically, decorators are just functions (or classes), that take a callable object as an argument, and return ananalogous object with the decoration.</description>
<category>Python</category>
<guid isPermaLink="true">https://ask.ghassem.com/472/what-are-decorators?show=473#a473</guid>
<pubDate>Mon, 29 Oct 2018 23:00:29 +0000</pubDate>
</item>
<item>
<title>Answered: What is a Magic class methods ?</title>
<link>https://ask.ghassem.com/470/what-is-a-magic-class-methods?show=471#a471</link>
<description>Magic class methods (not a complete list) Magic methods (which begin and end with double underscore) add functionality to your classes consistent with the broader language.</description>
<category>Python</category>
<guid isPermaLink="true">https://ask.ghassem.com/470/what-is-a-magic-class-methods?show=471#a471</guid>
<pubDate>Mon, 29 Oct 2018 22:58:07 +0000</pubDate>
</item>
<item>
<title>Answer selected: Hey, anyone knows how to save workspace in jupyter python? I would like to save the variables and functions, etc.</title>
<link>https://ask.ghassem.com/441/anyone-knows-workspace-jupyter-python-variables-functions?show=442#a442</link>
<description>&lt;p&gt;I think you need to use &lt;a rel=&quot;nofollow&quot; href=&quot;https://pypi.org/project/dill/&quot;&gt;&lt;strong&gt;dill&lt;/strong&gt;&lt;/a&gt; for this purpose.&amp;nbsp;&lt;br&gt;
&lt;strong&gt;&lt;code&gt;&quot;dill&lt;/code&gt;&lt;/strong&gt;&amp;nbsp;extends python’s&amp;nbsp;&lt;strong&gt;&lt;code&gt;pickle&lt;/code&gt;&lt;/strong&gt;&amp;nbsp;module for serializing and de-serializing python objects to the majority of the built-in python types. Serialization is the process of converting an object to a byte stream, and the inverse of which is converting a byte stream back to on python object hierarchy.&quot;&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-python&quot; data-pbcklang=&quot;python&quot; data-pbcktabsize=&quot;4&quot;&gt;
conda install -c anaconda dill &lt;/pre&gt;

&lt;p&gt;To save the&amp;nbsp;Jupyter Notebook session:&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-python&quot; data-pbcklang=&quot;python&quot; data-pbcktabsize=&quot;4&quot;&gt;
import dill
dill.dump_session(&#039;notebook_session.db&#039;)&lt;/pre&gt;

&lt;p&gt;To restore the &amp;nbsp;session:&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-python&quot; data-pbcklang=&quot;python&quot; data-pbcktabsize=&quot;4&quot;&gt;
import dill
dill.load_session(&#039;notebook_session.db&#039;)&lt;/pre&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description>
<category>Python</category>
<guid isPermaLink="true">https://ask.ghassem.com/441/anyone-knows-workspace-jupyter-python-variables-functions?show=442#a442</guid>
<pubDate>Wed, 24 Oct 2018 21:28:38 +0000</pubDate>
</item>
<item>
<title>Answered: ploting the xticks to be datatime</title>
<link>https://ask.ghassem.com/432/ploting-the-xticks-to-be-datatime?show=434#a434</link>
<description>&lt;p&gt;Please take a look at the following code. I converted the data to time-series, and then showed how to resample it with a different frequency such 30 minutes. For 4 hours, change the first&amp;nbsp;&lt;strong&gt;resample&lt;/strong&gt; parameter to &lt;strong&gt;4H&lt;/strong&gt;.&amp;nbsp;&lt;/p&gt;

&lt;p&gt;You can run the code &lt;a rel=&quot;nofollow&quot; href=&quot;https://repl.it/@tofighi/plottimeseries&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-python&quot; data-pbcklang=&quot;python&quot; data-pbcktabsize=&quot;4&quot;&gt;
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import io

data = &quot;&quot;&quot;2012-01-01 00:15:00	3.807107	22.759602	00:15:00
2012-01-01 00:30:00	5.076142	22.759602	00:30:00
2012-01-01 00:45:00	3.807107	22.759602	00:45:00
2012-01-01 01:00:00	3.807107	22.759602	01:00:00
2012-01-01 01:15:00	5.076142	22.048364	01:15:00&quot;&quot;&quot;

df = pd.read_csv(io.StringIO(data), names =[&quot;date&quot;,&quot;time&quot;, &quot;MT1&quot;, &quot;MT2&quot;, &quot;hour&quot;], sep =&quot;\s+&quot;)
df.drop([&#039;hour&#039;], axis = 1, inplace = True) #removing redundant hour


#Creating timestamp column by merging date and time
df[&quot;timestamp&quot;] = (df[&quot;date&quot;].map(str) + &quot; &quot; + df[&quot;time&quot;])
df.index = pd.to_datetime(df[&quot;timestamp&quot;])
df.drop([&#039;date&#039;,&#039;timestamp&#039;], axis = 1, inplace = True)
df2 = df.resample(&#039;30Min&#039; ,base=0).last()
print(&quot;\ndf\n&quot;, df)
print(&quot;\ndf2\n&quot;,df2)

f, (ax1, ax2) = plt.subplots(1, 2,figsize=(20,5) )
ax1.plot(df[&#039;time&#039;], df[&#039;MT1&#039;],&#039;ro--&#039;)
ax2.plot(df2[&#039;time&#039;], df2[&#039;MT1&#039;],&#039;ro--&#039;)
ax1.plot(df[&#039;time&#039;], df[&#039;MT2&#039;],&#039;bo--&#039;)
ax2.plot(df2[&#039;time&#039;], df2[&#039;MT2&#039;],&#039;bo--&#039;)
ax1.grid(True)
ax2.grid(True)
ax1.legend()
ax2.legend()
plt.setp(ax1.xaxis.get_majorticklabels(), rotation=70, ha=&quot;right&quot;)
plt.setp(ax2.xaxis.get_majorticklabels(), rotation=70, ha=&quot;right&quot;)

plt.show()
plt.savefig(&#039;graph.png&#039;)&lt;/pre&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description>
<category>Python</category>
<guid isPermaLink="true">https://ask.ghassem.com/432/ploting-the-xticks-to-be-datatime?show=434#a434</guid>
<pubDate>Sun, 21 Oct 2018 22:18:58 +0000</pubDate>
</item>
<item>
<title>Answered: How can you tell a Python library is a good one and useful?</title>
<link>https://ask.ghassem.com/425/how-can-you-tell-a-python-library-is-a-good-one-and-useful?show=426#a426</link>
<description>&lt;p&gt;One of the features of GitHub is &lt;strong&gt;stars&lt;/strong&gt; developers give to a library and number of forks (copies). If the number of stars is high, it seems you are seeing a great library.&lt;/p&gt;</description>
<category>Python</category>
<guid isPermaLink="true">https://ask.ghassem.com/425/how-can-you-tell-a-python-library-is-a-good-one-and-useful?show=426#a426</guid>
<pubDate>Fri, 19 Oct 2018 03:48:16 +0000</pubDate>
</item>
<item>
<title>Commented: plotting categorical radio</title>
<link>https://ask.ghassem.com/414/plotting-categorical-radio?show=423#c423</link>
<description>Thanks for sharing. Two notes:&lt;br /&gt;
1) Please use code section on the toolbar when sharing your codes. &lt;br /&gt;
2) That would be great to provide executable version on &lt;a href=&quot;https://repl.it&quot; rel=&quot;nofollow&quot; target=&quot;_blank&quot;&gt;https://repl.it&lt;/a&gt;</description>
<category>Python</category>
<guid isPermaLink="true">https://ask.ghassem.com/414/plotting-categorical-radio?show=423#c423</guid>
<pubDate>Wed, 17 Oct 2018 20:59:44 +0000</pubDate>
</item>
<item>
<title>Answered: In a dataframe of a size (5,10) with random values, how to have exactly 5 NAN values in each row?</title>
<link>https://ask.ghassem.com/420/dataframe-size-with-random-values-have-exactly-values-each?show=422#a422</link>
<description>&lt;p&gt;You can create a random DataFrame, then generate random&amp;nbsp;column numbers and replace those columns for each row with NaN. You can run it &lt;a rel=&quot;nofollow&quot; href=&quot;https://repl.it/@tofighi/generate-random-NAN&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-python&quot; data-pbcklang=&quot;python&quot; data-pbcktabsize=&quot;4&quot;&gt;
import pandas as pd
import numpy as np
import random

rows = 5
cols = 10 
nan_n = 5

df = pd.DataFrame(np.random.randint(0,100,size=(rows, cols)))

print(df)
for row in range(0,rows):
    nan_cols = np.asarray(random.sample(range(0, 10), nan_n))
    df.at[row, nan_cols] = np.nan

print(df)&lt;/pre&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description>
<category>Python</category>
<guid isPermaLink="true">https://ask.ghassem.com/420/dataframe-size-with-random-values-have-exactly-values-each?show=422#a422</guid>
<pubDate>Wed, 17 Oct 2018 20:48:31 +0000</pubDate>
</item>
<item>
<title>My own transformation for dropping feature doesn&#039;t work</title>
<link>https://ask.ghassem.com/413/my-own-transformation-for-dropping-feature-doesnt-work</link>
<description>&lt;p&gt;I made my own transformation to drop some of the features not required in the dataframe but I can&#039;t seem to get it working. Thoughts ?&lt;/p&gt;

&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://repl.it/@Neo_sauga/HarmfulNearApplicationstack&quot;&gt;https://repl.it/@Neo_sauga/HarmfulNearApplicationstack&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description>
<category>Python</category>
<guid isPermaLink="true">https://ask.ghassem.com/413/my-own-transformation-for-dropping-feature-doesnt-work</guid>
<pubDate>Wed, 17 Oct 2018 00:52:29 +0000</pubDate>
</item>
<item>
<title>Answered: How to fetch the data from a url using Python?</title>
<link>https://ask.ghassem.com/399/how-to-fetch-the-data-from-a-url-using-python?show=401#a401</link>
<description>
&lt;p&gt;Use the following code, and do not forget the &lt;strong&gt;space&lt;/strong&gt; in URLs should be converted to&amp;nbsp;&lt;strong&gt;%20. &lt;/strong&gt;You can run the code &lt;a rel=&quot;nofollow&quot; href=&quot;https://repl.it/@tofighi/loadcreditdatastore&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;pre data-pbcklang=&quot;python&quot; data-pbcktabsize=&quot;4&quot;&gt;
import os
import urllib.request

def fetch_credit_card_data(url, directory, file_name):
    if not os.path.isdir(directory):
        os.makedirs(directory)
    urllib.request.urlretrieve(url, directory+&#039;/&#039;+file_name)


url = &quot;https://archive.ics.uci.edu/ml/machine-learning-databases/00350/default%20of%20credit%20card%20clients.xls&quot;
directory = &#039;directory&#039;
file_name = &#039;credit_card.xls&#039;

fetch_credit_card_data(url, directory, file_name)&lt;/pre&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;
</description>
<category>Python</category>
<guid isPermaLink="true">https://ask.ghassem.com/399/how-to-fetch-the-data-from-a-url-using-python?show=401#a401</guid>
<pubDate>Mon, 15 Oct 2018 20:33:57 +0000</pubDate>
</item>
<item>
<title>Answered: How to update &quot;conda&quot; version itself?</title>
<link>https://ask.ghassem.com/313/how-to-update-conda-version-itself?show=314#a314</link>
<description>&lt;p&gt;Please use the following command in your Terminal (Linux/Mac) or Command (Windows):&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-python&quot; data-pbcklang=&quot;python&quot; data-pbcktabsize=&quot;4&quot;&gt;
conda update -n base conda -c anaconda&lt;/pre&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description>
<category>Python</category>
<guid isPermaLink="true">https://ask.ghassem.com/313/how-to-update-conda-version-itself?show=314#a314</guid>
<pubDate>Wed, 10 Oct 2018 16:58:20 +0000</pubDate>
</item>
<item>
<title>Answered: Access denied while updating Anaconda?</title>
<link>https://ask.ghassem.com/198/access-denied-while-updating-anaconda?show=199#a199</link>
<description>&lt;p&gt;Do you have administrative privileges&amp;nbsp;to update Anaconda? You can try &lt;strong&gt;Run as administrator &lt;/strong&gt;this time when you run cmd (figure below: Right click on Command Prompt -&amp;gt; Run as administrator) to see if it gives you error&amp;nbsp;again.&amp;nbsp;&lt;/p&gt;

&lt;p&gt;&lt;img alt=&quot;&quot; height=&quot;324&quot; src=&quot;https://i.imgur.com/tpNOjB0.png&quot; width=&quot;292&quot;&gt;&lt;/p&gt;</description>
<category>Python</category>
<guid isPermaLink="true">https://ask.ghassem.com/198/access-denied-while-updating-anaconda?show=199#a199</guid>
<pubDate>Sun, 30 Sep 2018 04:54:44 +0000</pubDate>
</item>
<item>
<title>Answered: What is the difference between single quotation (&#039; &#039;) and double (&quot;&quot;) quotation in Python?</title>
<link>https://ask.ghassem.com/171/difference-between-single-quotation-double-quotation-python?show=172#a172</link>
<description>&lt;p&gt;A string as a sequence of characters not intended to have numeric value. In Python, such sequence of characters is included inside single or double quotes. As far as language syntax is concerned, &lt;strong&gt;there is no difference in single or double quoted string. &lt;/strong&gt;Both representations can be used interchangeably. However, if either single or double quote is a part of the string itself, then the string must be placed in double or single quotes respectively.&lt;/p&gt;

&lt;p&gt;For example a text Hello “Python” is to be stored as a string, then one should use:&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-c_cpp&quot; data-pbcklang=&quot;c_cpp&quot; data-pbcktabsize=&quot;4&quot;&gt;
str1=&#039;Hello &quot;Python&quot;&#039;
&lt;/pre&gt;

&lt;p&gt;On the other hand, if string should resemble Hello ‘Python’ then it should be declared as follows:&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-c_cpp&quot; data-pbcklang=&quot;c_cpp&quot; data-pbcktabsize=&quot;4&quot;&gt;
Str2=&quot;Hello &#039;Python&#039;&quot;&lt;/pre&gt;

&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.tutorialspoint.com/What-is-the-difference-between-single-and-double-quotes-in-python&quot;&gt;source&lt;/a&gt;&lt;/p&gt;</description>
<category>Python</category>
<guid isPermaLink="true">https://ask.ghassem.com/171/difference-between-single-quotation-double-quotation-python?show=172#a172</guid>
<pubDate>Fri, 28 Sep 2018 14:37:44 +0000</pubDate>
</item>
<item>
<title>Answer selected: What do L1-norm and L2-norm mean as it applies to Norm?</title>
<link>https://ask.ghassem.com/149/what-do-l1-norm-and-l2-norm-mean-as-it-applies-to-norm?show=152#a152</link>
<description>&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.kaggle.com/residentmario/l1-norms-versus-l2-norms&quot;&gt;This article&lt;/a&gt;&amp;nbsp;describes both of them in more details, but in short, &lt;strong&gt;we define&amp;nbsp;$|| x ||_p$ as p-norm&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;p-norm:&lt;/strong&gt;&amp;nbsp;Given $x$, a vector with&amp;nbsp;$i$ components, a &lt;em&gt;p-norm&lt;/em&gt; is defined as:&lt;/p&gt;

&lt;p&gt;$|| x ||_p = \left(\sum_i |x_i|^p\right)^{1/p}$&amp;nbsp;&lt;/p&gt;

&lt;p&gt;The simplest norm conceptually is &lt;strong&gt;Euclidean distance&lt;/strong&gt;. This is what we typically think of as distance between two points in space:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2-norm (Euclidean distance ro L2-norm)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;$|| x ||_2 = \sqrt{\left(\sum_i x_i^2\right)} = \sqrt{x_1^2 + x_2^2 + \ldots + x_i^2}$&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1-norm&amp;nbsp;(Manhattan distance&lt;/strong&gt; or &lt;strong&gt;L1-norm)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;$|| x ||_1 = \sum_i |x_i| = |x_1| + |x_2| + \ldots + |x_i|$&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;&lt;br&gt;
Python implementation&lt;/h2&gt;

&lt;p&gt;If you want to calculate them in Python,&amp;nbsp;&lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;http:// https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.linalg.norm.html&quot;&gt;numpy&lt;/a&gt;&lt;/strong&gt;&lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;http:// https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.linalg.norm.html&quot;&gt;.linalg.norm&lt;/a&gt;&amp;nbsp;&lt;/strong&gt;provides functions for it. In addition, you can use&amp;nbsp;&lt;strong&gt;Distance computations (&lt;/strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://docs.scipy.org/doc/scipy/reference/spatial.distance.html&quot;&gt;&lt;strong&gt;scipy&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://docs.scipy.org/doc/scipy/reference/spatial.distance.html&quot;&gt;.spatial.distance&lt;/a&gt;) &lt;/strong&gt;library. For example, for the&amp;nbsp;&lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.distance.euclidean.html#scipy.spatial.distance.euclidean&quot;&gt;Euclidean distance&lt;/a&gt;&lt;/strong&gt; between two vectors, $a$ and $b$, you can use the following code:&lt;/p&gt;

&lt;pre&gt;
from scipy.spatial import distance
distance.euclidean(a, b)
&lt;/pre&gt;

&lt;p&gt;and if you want to calculate the &lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.distance.cityblock.html#scipy.spatial.distance.cityblock&quot;&gt;Manhattan distance&lt;/a&gt;&lt;/strong&gt;, you can use the following code:&lt;/p&gt;

&lt;pre&gt;
from scipy.spatial import distance
distance.cityblock(a, b)
&lt;/pre&gt;

&lt;p&gt;How did I know this time it is called &lt;strong&gt;cityblock&lt;/strong&gt;? I read &lt;a rel=&quot;nofollow&quot; href=&quot;https://docs.scipy.org/doc/scipy/reference/spatial.distance.html&quot;&gt;the documentation&lt;/a&gt; and looked up for Manhattan distance.&lt;/p&gt;</description>
<category>Python</category>
<guid isPermaLink="true">https://ask.ghassem.com/149/what-do-l1-norm-and-l2-norm-mean-as-it-applies-to-norm?show=152#a152</guid>
<pubDate>Wed, 26 Sep 2018 15:41:08 +0000</pubDate>
</item>
<item>
<title>Answered: Can someone please post the video tutorial for Pandas, Numpy and Matplotlib ?</title>
<link>https://ask.ghassem.com/69/someone-please-post-video-tutorial-pandas-numpy-matplotlib?show=73#a73</link>
<description>&lt;p&gt;There are many good tutorials out there. For Lynda.com (&lt;a rel=&quot;nofollow&quot; href=&quot;https://askdatascience.com/24/how-to-use-lynda-com-for-free&quot;&gt;here you can see you to use it for free&lt;/a&gt;), I recommend the following tutorials.&lt;/p&gt;

&lt;ul&gt;
	&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.lynda.com/NumPy-tutorials/NumPy-Data-Science-Essential-Training/508873-2.html&quot;&gt;&lt;strong&gt;NumPy Data Science Essential Training&lt;/strong&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;(4 hours)&lt;/li&gt;
	&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.lynda.com/Pandas-tutorials/pandas-Data-Science/518161-2.html&quot;&gt;&lt;strong&gt;Pandas for Data Science&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;&amp;nbsp;&lt;/strong&gt;(2 hours)&lt;/li&gt;
	&lt;li&gt;&lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.lynda.com/Python-tutorials/Overview-matplotlib/550457/628315-4.html&quot;&gt;Matplotlib&lt;/a&gt;&amp;nbsp;&lt;/strong&gt;(20 minutes)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can also take all of them all to together in a shorter series in&amp;nbsp;&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.lynda.com/Python-tutorials/Data-Science-Foundations-Python-Scientific-Stack/550457-2.html&quot;&gt;&lt;strong&gt;Data Science Foundations: Python Scientific Stack&lt;/strong&gt;&lt;/a&gt;&amp;nbsp;(3.5 hours) course.&lt;/p&gt;</description>
<category>Python</category>
<guid isPermaLink="true">https://ask.ghassem.com/69/someone-please-post-video-tutorial-pandas-numpy-matplotlib?show=73#a73</guid>
<pubDate>Wed, 19 Sep 2018 18:51:30 +0000</pubDate>
</item>
</channel>
</rss>