text stringlengths 81 47k | source stringlengths 59 147 |
|---|---|
Question: <p>I am trying to save a csv to a folder after making some edits to the file. </p>
<p>Every time I use <code>pd.to_csv('C:/Path of file.csv')</code> the csv file has a separate column of indexes. I want to avoid printing the index to csv.</p>
<p>I tried: </p>
<pre><code>pd.read_csv('C:/Path to file to edit... | https://stackoverflow.com/questions/20845213/how-to-avoid-pandas-creating-an-index-in-a-saved-csv |
Question: <p>Can you tell me when to use these vectorization methods with basic examples? </p>
<p>I see that <code>map</code> is a <code>Series</code> method whereas the rest are <code>DataFrame</code> methods. I got confused about <code>apply</code> and <code>applymap</code> methods though. Why do we have two methods... | https://stackoverflow.com/questions/19798153/difference-between-map-applymap-and-apply-methods-in-pandas |
Question: <p>I have a dataframe <code>df</code> and I use several columns from it to <code>groupby</code>:</p>
<pre class="lang-py prettyprint-override"><code>df['col1','col2','col3','col4'].groupby(['col1','col2']).mean()
</code></pre>
<p>In the above way, I almost get the table (dataframe) that I need. What is missin... | https://stackoverflow.com/questions/19384532/get-statistics-for-each-group-such-as-count-mean-etc-using-pandas-groupby |
Question: <p>How do I check whether a pandas DataFrame has NaN values?</p>
<p>I know about <code>pd.isnan</code> but it returns a DataFrame of booleans. I also found <a href="https://stackoverflow.com/questions/27754891/python-nan-value-in-pandas">this post</a> but it doesn't exactly answer my question either.</p>
Ans... | https://stackoverflow.com/questions/29530232/how-to-check-if-any-value-is-nan-in-a-pandas-dataframe |
Question: <p>I have created a Pandas DataFrame</p>
<pre class="lang-py prettyprint-override"><code>df = DataFrame(index=['A','B','C'], columns=['x','y'])
</code></pre>
<p>Now, I would like to assign a value to particular cell, for example to row <code>C</code> and column <code>x</code>. In other words, I would like to ... | https://stackoverflow.com/questions/13842088/set-value-for-particular-cell-in-pandas-dataframe-using-index |
Question: <p>I would like to read several CSV files from a directory into pandas and concatenate them into one big DataFrame. I have not been able to figure it out though. Here is what I have so far:</p>
<pre><code>import glob
import pandas as pd
# Get data file names
path = r'C:\DRO\DCL_rawdata_files'
filenames = glo... | https://stackoverflow.com/questions/20906474/import-multiple-csv-files-into-pandas-and-concatenate-into-one-dataframe |
Question: <p>Suppose I have a function and a dataframe defined as below:</p>
<pre class="lang-py prettyprint-override"><code>def get_sublist(sta, end):
return mylist[sta:end+1]
df = pd.DataFrame({'ID':['1','2','3'], 'col_1': [0,2,3], 'col_2':[1,4,5]})
mylist = ['a','b','c','d','e','f']
</code></pre>
<p>Now I want ... | https://stackoverflow.com/questions/13331698/how-to-apply-a-function-to-two-columns-of-pandas-dataframe |
Question: <p>I have constructed a condition that extracts exactly one row from my dataframe:</p>
<pre class="lang-py prettyprint-override"><code>d2 = df[(df['l_ext']==l_ext) & (df['item']==item) & (df['wn']==wn) & (df['wd']==1)]
</code></pre>
<p>Now I would like to take a value from a particular column:</p>... | https://stackoverflow.com/questions/16729574/how-can-i-get-a-value-from-a-cell-of-a-dataframe |
Question: <p>I am getting a <code>ValueError: cannot reindex from a duplicate axis</code> when I am trying to set an index to a certain value. I tried to reproduce this with a simple example, but I could not do it.</p>
<p>Here is my session inside of <code>ipdb</code> trace. I have a DataFrame with string index, and i... | https://stackoverflow.com/questions/27236275/what-does-valueerror-cannot-reindex-from-a-duplicate-axis-mean |
Question: <p>I have a Python pandas DataFrame <code>rpt</code>:</p>
<pre><code>rpt
<class 'pandas.core.frame.DataFrame'>
MultiIndex: 47518 entries, ('000002', '20120331') to ('603366', '20091231')
Data columns:
STK_ID 47518 non-null values
STK_Name 47518 non-null values
RPT_... | https://stackoverflow.com/questions/12065885/filter-dataframe-rows-if-value-in-column-is-in-a-set-list-of-values |
Question: <p>I'm running a program which is processing 30,000 similar files. A random number of them are stopping and producing this error...</p>
<pre class="lang-none prettyprint-override"><code> File "C:\Importer\src\dfman\importer.py", line 26, in import_chr
data = pd.read_csv(filepath, names=fields)
... | https://stackoverflow.com/questions/18171739/unicodedecodeerror-when-reading-csv-file-in-pandas |
Question: <p>How do I convert a Pandas dataframe into a NumPy array?</p>
<pre class="lang-py prettyprint-override"><code>import numpy as np
import pandas as pd
df = pd.DataFrame(
{
'A': [np.nan, np.nan, np.nan, 0.1, 0.1, 0.1, 0.1],
'B': [0.2, np.nan, 0.2, 0.2, 0.2, np.nan, np.nan],
'C': [np... | https://stackoverflow.com/questions/13187778/convert-pandas-dataframe-to-numpy-array |
Question: <p>How do I check if a pandas <code>DataFrame</code> is empty? I'd like to print some message in the terminal if the <code>DataFrame</code> is empty.</p>
Answer: <p>You can use the attribute <code>df.empty</code> to check whether it's empty or not:</p>
<pre><code>if df.empty:
print('DataFrame is empty!')... | https://stackoverflow.com/questions/19828822/how-do-i-check-if-a-pandas-dataframe-is-empty |
Question: <p>I have a dataframe like this:</p>
<pre class="lang-none prettyprint-override"><code> 0 1 2
0 354.7 April 4.0
1 55.4 August 8.0
2 176.5 December 12.0
3 95.5 February 2.0
4 85.6 January 1.0
5 152 July 7.0
6 238.7 June 6.0
7 104... | https://stackoverflow.com/questions/37787698/how-to-sort-pandas-dataframe-by-one-column |
Question: <p>I have a dataframe:</p>
<pre class="lang-none prettyprint-override"><code> City Name
0 Seattle Alice
1 Seattle Bob
2 Portland Mallory
3 Seattle Mallory
4 Seattle Bob
5 Portland Mallory
</code></pre>
<p>I perform the following grouping:</p>
<pre class="lang-py prettyprint-ove... | https://stackoverflow.com/questions/10373660/converting-a-pandas-groupby-multiindex-output-from-series-back-to-dataframe |
Question: <p>This seems like a ridiculously easy question... but I'm not seeing the easy answer I was expecting.</p>
<p>So, how do I get the value at an nth row of a given column in Pandas? (I am particularly interested in the first row, but would be interested in a more general practice as well).</p>
<p>For example, l... | https://stackoverflow.com/questions/25254016/pandas-get-first-row-value-of-a-given-column |
Question: <p>I have a Pandas Dataframe as below:</p>
<pre class="lang-none prettyprint-override"><code> itm Date Amount
67 420 2012-09-30 00:00:00 65211
68 421 2012-09-09 00:00:00 29424
69 421 2012-09-16 00:00:00 29877
70 421 2012-09-23 00:00:00 30990
71 421 2012-09-30 00:0... | https://stackoverflow.com/questions/13295735/how-to-replace-nan-values-in-a-dataframe-column |
Question: <p>I have a Python dictionary:</p>
<pre class="lang-py prettyprint-override"><code>{u'2012-07-01': 391,
u'2012-07-02': 392,
u'2012-07-03': 392,
u'2012-07-04': 392,
u'2012-07-05': 392,
u'2012-07-06': 392}
</code></pre>
<p>I would like to convert this into a pandas dataframe by having the dates and their c... | https://stackoverflow.com/questions/18837262/convert-python-dict-into-a-dataframe |
Question: <p>How do I check if a column exists in a Pandas DataFrame <code>df</code>?</p>
<pre class="lang-none prettyprint-override"><code> A B C
0 3 40 100
1 6 30 200
</code></pre>
<p>How would I check if the column <code>"A"</code> exists in the above DataFrame so that I can compute:</p>
<pre ... | https://stackoverflow.com/questions/24870306/how-to-check-if-a-column-exists-in-pandas |
Question: <p>I would like to create views or dataframes from an existing dataframe based on column selections.</p>
<p>For example, I would like to create a dataframe <code>df2</code> from a dataframe <code>df1</code> that holds all columns from it except two of them. I tried doing the following, but it didn't work:</p... | https://stackoverflow.com/questions/14940743/selecting-excluding-sets-of-columns-in-pandas |
Question: <p>I have a <code>dataframe</code> with over 200 columns. The issue is as they were generated the order is</p>
<pre><code>['Q1.3','Q6.1','Q1.2','Q1.1',......]
</code></pre>
<p>I need to <em>sort</em> the columns as follows:</p>
<pre><code>['Q1.1','Q1.2','Q1.3',.....'Q6.1',......]
</code></pre>
<p>Is there som... | https://stackoverflow.com/questions/11067027/sorting-columns-in-pandas-dataframe-based-on-column-name |
Question: <p>I have a dataframe from which I remove some rows. As a result, I get a dataframe in which index is something like <code>[1,5,6,10,11]</code> and I would like to reset it to <code>[0,1,2,3,4]</code>. How can I do it?</p>
<hr />
<p>The following seems to work:</p>
<pre class="lang-py prettyprint-override"><c... | https://stackoverflow.com/questions/20490274/how-to-reset-index-in-a-pandas-dataframe |
Question: <p>I want to apply my custom function (it uses an if-else ladder) to these six columns (<code>ERI_Hispanic</code>, <code>ERI_AmerInd_AKNatv</code>, <code>ERI_Asian</code>, <code>ERI_Black_Afr.Amer</code>, <code>ERI_HI_PacIsl</code>, <code>ERI_White</code>) in each row of my dataframe.</p>
<p>I've tried differ... | https://stackoverflow.com/questions/26886653/create-new-column-based-on-values-from-other-columns-apply-a-function-of-multi |
Question: <p>I converted a Pandas dataframe to an HTML output using the <code>DataFrame.to_html</code> function. When I save this to a separate HTML file, the file shows truncated output.</p>
<p>For example, in my TEXT column,</p>
<p><code>df.head(1)</code> will show</p>
<p><em>The film was an excellent effort...</em><... | https://stackoverflow.com/questions/25351968/how-can-i-display-full-non-truncated-dataframe-information-in-html-when-conver |
Question: <p>I have a data frame with a hierarchical index in axis 1 (columns) (from a <code>groupby.agg</code> operation):</p>
<pre><code> USAF WBAN year month day s_PC s_CL s_CD s_CNT tempf
sum sum sum sum amax amin
0 702730 26451 1993 1 ... | https://stackoverflow.com/questions/14507794/how-to-flatten-a-hierarchical-index-in-columns |
Question: <p><strong>How do I pivot the pandas dataframe <code>df</code> defined at bottom such that the <code>col</code> values become columns, <code>row</code> values become the index, and mean of <code>val0</code> becomes the values?</strong> (in some cases this is called transforming from long-format to wide-format... | https://stackoverflow.com/questions/47152691/how-can-i-pivot-a-dataframe |
Question: <p>I have a fairly large dataset in the form of a dataframe and I was wondering how I would be able to split the dataframe into two random samples (80% and 20%) for training and testing.</p>
<p>Thanks!</p>
Answer: <p>I would just use numpy's <code>randn</code>:</p>
<pre><code>In [11]: df = pd.DataFrame(np.... | https://stackoverflow.com/questions/24147278/how-do-i-create-test-and-train-samples-from-one-dataframe-with-pandas |
Question: <p>Given a DataFrame with a column "BoolCol", we want to find the indexes of the DataFrame in which the values for "BoolCol" == True</p>
<p>I currently have the iterating way to do it, which works perfectly:</p>
<pre class="lang-py prettyprint-override"><code>for i in range(100,3000):
... | https://stackoverflow.com/questions/21800169/python-pandas-get-index-of-rows-where-column-matches-certain-value |
Question: <p>I have a dictionary which looks like this: <code>di = {1: "A", 2: "B"}</code></p>
<p>I would like to apply it to the <code>col1</code> column of a dataframe similar to:</p>
<pre class="lang-none prettyprint-override"><code> col1 col2
0 w a
1 1 2
2 2 ... | https://stackoverflow.com/questions/20250771/remap-values-in-pandas-column-with-a-dict-preserve-nans |
Question: <p>Right now I'm importing a fairly large <code>CSV</code> as a dataframe every time I run the script. Is there a good solution for keeping that dataframe constantly available in between runs so I don't have to spend all that time waiting for the script to run?</p>
Answer: <p>The easiest way is to <a href="h... | https://stackoverflow.com/questions/17098654/how-to-reversibly-store-and-load-a-pandas-dataframe-to-from-disk |
Question: <pre><code>df = pd.read_csv('somefile.csv')
</code></pre>
<p>...gives an error:</p>
<blockquote>
<p>.../site-packages/pandas/io/parsers.py:1130:
DtypeWarning: Columns (4,5,7,16) have mixed types. Specify dtype
option on import or set low_memory=False.</p>
</blockquote>
<p>Why is the <code>dtype</code> option... | https://stackoverflow.com/questions/24251219/pandas-read-csv-low-memory-and-dtype-options |
Question: <p>If I've got a multi-level column index:</p>
<pre><code>>>> cols = pd.MultiIndex.from_tuples([("a", "b"), ("a", "c")])
>>> pd.DataFrame([[1,2], [3,4]], columns=cols)
</code></pre>
<pre>
a
---+--
b | c
--+---+--
0 | 1 | 2
1 | 3 | 4
</pre>
<p>How can I drop the "a" level of tha... | https://stackoverflow.com/questions/22233488/pandas-drop-a-level-from-a-multi-level-column-index |
Question: <p>I need to generate a whole bunch of vertically-stacked plots in matplotlib. The result will be saved using <code>savefig</code> and viewed on a webpage, so I don't care how tall the final image is, as long as the subplots are spaced so they don't overlap.</p>
<p>No matter how big I allow the figure to be, ... | https://stackoverflow.com/questions/6541123/improve-subplot-size-spacing-with-many-subplots |
Question: <p>Given a dataframe, I want to groupby the first column and get second column as lists in rows, so that a dataframe like:</p>
<pre><code>a b
A 1
A 2
B 5
B 5
B 4
C 6
</code></pre>
<p>becomes</p>
<pre><code>A [1,2]
B [5,5,4]
C [6]
</code></pre>
<p>How do I do this?</p>
Answer: <p>You can do this using <code>g... | https://stackoverflow.com/questions/22219004/how-to-group-dataframe-rows-into-list-in-pandas-groupby |
Question: <p>I have a dataframe <code>df</code> imported from an Excel document like this:</p>
<pre class="lang-none prettyprint-override"><code>cluster load_date budget actual fixed_price
A 1/1/2014 1000 4000 Y
A 2/1/2014 12000 10000 Y
A 3/1/2014 36000 2000 Y
B 4/1/2014 15000 1... | https://stackoverflow.com/questions/22341271/get-list-from-pandas-dataframe-column-or-row |
Question: <p>I am curious as to why <code>df[2]</code> is not supported, while <code>df.ix[2]</code> and <code>df[2:3]</code> both work. </p>
<pre><code>In [26]: df.ix[2]
Out[26]:
A 1.027680
B 1.514210
C -1.466963
D -0.162339
Name: 2000-01-03 00:00:00
In [27]: df[2:3]
Out[27]:
A B... | https://stackoverflow.com/questions/16096627/selecting-a-row-of-pandas-series-dataframe-by-integer-index |
Question: <p>I have a pandas dataframe with multiple columns. I want to change the values of the only the first column without affecting the other columns. How can I do that using <a href="https://pandas.pydata.org/docs/reference/api/pandas.Series.apply.html" rel="noreferrer"><code>apply()</code></a> in pandas?</p>
An... | https://stackoverflow.com/questions/34962104/how-can-i-use-the-apply-function-for-a-single-column |
Question: <p>I have a dataframe that look like this:</p>
<pre class="lang-none prettyprint-override"><code> a b c d
0 0.418762 0.042369 0.869203 0.972314
1 0.991058 0.510228 0.594784 0.534366
2 0.407472 0.259811 0.396664 0.894202
3 0.726168 0.139531 0.324932 0.906575
</c... | https://stackoverflow.com/questions/29763620/how-to-select-all-columns-except-one-in-pandas |
Question: <p>What's the easiest way to add an empty column to a pandas DataFrame object? The best I've stumbled upon is something like</p>
<pre class="lang-py prettyprint-override"><code>df['foo'] = df.apply(lambda _: '', axis=1)
</code></pre>
<p>Is there a less perverse method?</p>
Answer: <p>If I understand correct... | https://stackoverflow.com/questions/16327055/how-to-add-an-empty-column-to-a-dataframe |
Question: <p>How do I add a <code>color</code> column to the following dataframe so that <code>color='green'</code> if <code>Set == 'Z'</code>, and <code>color='red'</code> otherwise?</p>
<pre><code> Type Set
1 A Z
2 B Z
3 B X
4 C Y
</code></pre>
Answer: <p><strong>If you only... | https://stackoverflow.com/questions/19913659/how-do-i-create-a-new-column-where-the-values-are-selected-based-on-an-existing |
Question: <p>Given a plot of a signal in time representation, how can I draw lines marking the corresponding time index?</p>
<p>Specifically, given a signal plot with a time index ranging from 0 to 2.6 (seconds), I want to draw vertical red lines indicating the corresponding time index for the list <code>[0.22058956, 0... | https://stackoverflow.com/questions/24988448/how-to-draw-vertical-lines-on-a-given-plot |
Question: <p>I've two pandas data frames that have some rows in common.</p>
<p>Suppose dataframe2 is a subset of dataframe1.</p>
<p><strong>How can I get the rows of dataframe1 which are not in dataframe2?</strong></p>
<pre><code>df1 = pandas.DataFrame(data = {'col1' : [1, 2, 3, 4, 5], 'col2' : [10, 11, 12, 13, 14]})
... | https://stackoverflow.com/questions/28901683/pandas-get-rows-which-are-not-in-other-dataframe |
Question: <p>Most operations in <code>pandas</code> can be accomplished with operator chaining (<code>groupby</code>, <code>aggregate</code>, <code>apply</code>, etc), but the only way I've found to filter rows is via normal bracket indexing</p>
<pre><code>df_filtered = df[df['column'] == value]
</code></pre>
<p>This... | https://stackoverflow.com/questions/11869910/pandas-filter-rows-of-dataframe-with-operator-chaining |
Question: <p>Here is my code to generate a dataframe:</p>
<pre><code>import pandas as pd
import numpy as np
dff = pd.DataFrame(np.random.randn(1, 2), columns=list('AB'))
</code></pre>
<p>then I got the dataframe:</p>
<pre><code> A B
0 0.626386 1.52325
</code></pre>
<p>When I type the command <code>df... | https://stackoverflow.com/questions/22149584/what-does-axis-in-pandas-mean |
Question: <p>I have a dataframe in pandas where each column has different value range. For example:</p>
<p>df:</p>
<pre><code>A B C
1000 10 0.5
765 5 0.35
800 7 0.09
</code></pre>
<p>Any idea how I can normalize the columns of this dataframe where each value is between 0 and 1?</p>
<p>My desired out... | https://stackoverflow.com/questions/26414913/normalize-columns-of-a-dataframe |
Question: <p>How to remove rows with duplicate index values?</p>
<p>In the weather DataFrame below, sometimes a scientist goes back and corrects observations -- not by editing the erroneous rows, but by appending a duplicate row to the end of a file.</p>
<p>I'm reading some automated weather data from the web (observat... | https://stackoverflow.com/questions/13035764/remove-pandas-rows-with-duplicate-indices |
Question: <p>How do I convert a <code>numpy.datetime64</code> object to a <code>datetime.datetime</code> (or <code>Timestamp</code>)?</p>
<p>In the following code, I create a datetime, timestamp and datetime64 objects.</p>
<pre><code>import datetime
import numpy as np
import pandas as pd
dt = datetime.datetime(2012, ... | https://stackoverflow.com/questions/13703720/converting-between-datetime-timestamp-and-datetime64 |
Question: <p>I have a dataframe df :</p>
<pre><code>>>> df
sales discount net_sales cogs
STK_ID RPT_Date
600141 20060331 2.709 NaN 2.709 2.245
20060630 6.590 NaN 6.590 5.291
20060930 10.103 NaN 1... | https://stackoverflow.com/questions/14661701/how-to-drop-a-list-of-rows-from-pandas-dataframe |
Question: <p>Suppose I have a dataframe with columns <code>a</code>, <code>b</code> and <code>c</code>. I want to sort the dataframe by column <code>b</code> in ascending order, and by column <code>c</code> in descending order. How do I do this?</p>
Answer: <p>As of the 0.17.0 release, the <a href="http://pandas.pydat... | https://stackoverflow.com/questions/17141558/how-to-sort-a-pandas-dataframe-by-two-or-more-columns |
Question: <p>Can I insert a column at a specific column index in pandas? </p>
<pre><code>import pandas as pd
df = pd.DataFrame({'l':['a','b','c','d'], 'v':[1,2,1,2]})
df['n'] = 0
</code></pre>
<p>This will put column <code>n</code> as the last column of <code>df</code>, but isn't there a way to tell <code>df</code> t... | https://stackoverflow.com/questions/18674064/how-do-i-insert-a-column-at-a-specific-column-index-in-pandas |
Question: <p>I want to know if it is possible to use the pandas <code>to_csv()</code> function to add a dataframe to an existing csv file. The csv file has the same structure as the loaded data. </p>
Answer: <p>You can specify a python write mode in the pandas <a href="http://pandas.pydata.org/pandas-docs/stable/gener... | https://stackoverflow.com/questions/17530542/how-to-add-pandas-data-to-an-existing-csv-file |
Question: <p>I have a dataset</p>
<pre class="lang-none prettyprint-override"><code>category
cat a
cat b
cat a
</code></pre>
<p>I'd like to return something like the following which shows the unique values and their frequencies</p>
<pre class="lang-none prettyprint-override"><code>category freq
cat a 2
cat b ... | https://stackoverflow.com/questions/22391433/count-the-frequency-that-a-value-occurs-in-a-dataframe-column |
Question: <p>I have a Dataframe, <code>df</code>, with the following column:</p>
<pre class="lang-none prettyprint-override"><code> ArrivalDate
936 2012-12-31
938 2012-12-29
965 2012-12-31
966 2012-12-31
967 2012-12-31
968 2012-12-31
969 2012-12-31
970 2012-12-29
971 2012-12-31
972 2012-12-29
97... | https://stackoverflow.com/questions/25146121/extracting-just-month-and-year-separately-from-pandas-datetime-column |
Question: <p>I have an existing dataframe which I need to add an additional column to which will contain the same value for every row.</p>
<p>Existing df:</p>
<pre><code>Date, Open, High, Low, Close
01-01-2015, 565, 600, 400, 450
</code></pre>
<p>New df:</p>
<pre><code>Name, Date, Open, High, Low, Close
abc, 01-01-... | https://stackoverflow.com/questions/29517072/add-column-to-dataframe-with-constant-value |
Question: <p>How do I find all rows in a pandas DataFrame which have the max value for <code>count</code> column, after grouping by <code>['Sp','Mt']</code> columns?</p>
<p><strong>Example 1:</strong> the following DataFrame:</p>
<pre><code> Sp Mt Value count
0 MM1 S1 a **3**
1 MM1 S1 n 2
2 MM1... | https://stackoverflow.com/questions/15705630/get-the-rows-which-have-the-max-value-in-groups-using-groupby |
Question: <p>In order to test some functionality I would like to create a <code>DataFrame</code> from a string. Let's say my test data looks like:</p>
<pre><code>TESTDATA="""col1;col2;col3
1;4.4;99
2;4.5;200
3;4.7;65
4;3.2;140
"""
</code></pre>
<p>What is the simplest way to read that data into a Pandas <code>DataFra... | https://stackoverflow.com/questions/22604564/create-pandas-dataframe-from-a-string |
Question: <p>I have a data frame with one (string) column and I'd like to split it into two (string) columns, with one column header as '<code>fips'</code> and the other <code>'row'</code></p>
<p>My dataframe <code>df</code> looks like this:</p>
<pre><code> row
0 00000 UNITED STATES
1 01000 ALABAMA
2 ... | https://stackoverflow.com/questions/14745022/how-to-split-a-dataframe-string-column-into-two-columns |
Question: <p>How do I drop <code>nan</code>, <code>inf</code>, and <code>-inf</code> values from a <code>DataFrame</code> without resetting <code>mode.use_inf_as_null</code>?</p>
<p>Can I tell <code>dropna</code> to include <code>inf</code> in its definition of missing values so that the following works?</p>
<pre><code... | https://stackoverflow.com/questions/17477979/dropping-infinite-values-from-dataframes-in-pandas |
Question: <p>I have a DataFrame with four columns. I want to convert this DataFrame to a python dictionary. I want the elements of first column be <code>keys</code> and the elements of other columns in the same row be <code>values</code>.</p>
<p>DataFrame:</p>
<pre class="lang-py prettyprint-override"><code> ID A ... | https://stackoverflow.com/questions/26716616/convert-a-pandas-dataframe-to-a-dictionary |
Question: <p>I have one field in a pandas DataFrame that was imported as string format.</p>
<p>It should be a datetime variable. How do I convert it to a datetime column, and then filter based on date?</p>
<p>Example:</p>
<pre class="lang-py prettyprint-override"><code>raw_data = pd.DataFrame({'Mycol': ['05SEP2014:00:0... | https://stackoverflow.com/questions/26763344/convert-pandas-column-to-datetime |
Question: <p>I am trying to determine whether there is an entry in a Pandas column that has a particular value. I tried to do this with <code>if x in df['id']</code>. I thought this was working, except when I fed it a value that I knew was not in the column <code>43 in df['id']</code> it still returned <code>True</code... | https://stackoverflow.com/questions/21319929/how-to-determine-whether-a-pandas-column-contains-a-particular-value |
Question: <p>I have a scatter plot graph with a bunch of random x, y coordinates. Currently the Y-Axis starts at 0 and goes up to the max value. I would like the Y-Axis to start at the max value and go up to 0.</p>
<pre><code>points = [(10,5), (5,11), (24,13), (7,8)]
x_arr = []
y_arr = []
for x,y in points:
x_... | https://stackoverflow.com/questions/2051744/how-to-invert-the-x-or-y-axis |
Question: <p>I have a dataframe that consist of hundreds of columns, and I need to see all column names.</p>
<p>What I did:</p>
<pre><code>In[37]:
data_all2.columns
</code></pre>
<p>The output is:</p>
<pre><code>Out[37]:
Index(['customer_id', 'incoming', 'outgoing', 'awan', 'bank', 'family', 'food',
'governm... | https://stackoverflow.com/questions/49188960/how-to-show-all-columns-names-on-a-large-pandas-dataframe |
Question: <p>Is it possible to append to an empty data frame that doesn't contain any indices or columns?</p>
<p>I have tried to do this, but keep getting an empty dataframe at the end.</p>
<p>e.g.</p>
<pre><code>import pandas as pd
df = pd.DataFrame()
data = ['some kind of data here' --> I have checked the type al... | https://stackoverflow.com/questions/16597265/appending-to-an-empty-dataframe-in-pandas |
Question: <p>How can I convert a DataFrame column of strings (in <em><strong>dd/mm/yyyy</strong></em> format) to datetime dtype?</p>
Answer: <p>The easiest way is to use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.to_datetime.html" rel="noreferrer"><code>to_datetime</code></a>:</p>
<pre><code... | https://stackoverflow.com/questions/17134716/convert-dataframe-column-type-from-string-to-datetime |
Question: <p>What is the easiest way to remove duplicate columns from a dataframe?</p>
<p>I am reading a text file that has duplicate columns via:</p>
<pre><code>import pandas as pd
df=pd.read_table(fname)
</code></pre>
<p>The column names are:</p>
<pre><code>Time, Time Relative, N2, Time, Time Relative, H2, etc..... | https://stackoverflow.com/questions/14984119/python-pandas-remove-duplicate-columns |
Question: <p>I checked them,
python --version
Python 3.7.1</p>
<p>pip --version
pip 18.1</p>
<p>and I'm using Windows 10.</p>
<p>but,pip install tenserflow running command line,The following error comes out.</p>
<p>pip is configured with locations that require TLS/SSL, however the ssl module in Python is not availa... | https://stackoverflow.com/questions/54931918/pip-install-tenserflow-in-command |
Question: <p>Is it worth installing Tenserflow on a <strong>NVIDIA GeForce MX230</strong> (It is CUDA Supported ). <a href="https://www.nvidia.com/en-us/geforce/gaming-laptops/geforce-mx230/specifications/" rel="nofollow noreferrer">https://www.nvidia.com/en-us/geforce/gaming-laptops/geforce-mx230/specifications/</a> o... | https://stackoverflow.com/questions/67633123/installing-tenserflow-on-gpu-nvidia-geforce-mx230 |
Question: <p>I'm using Electron + ReactJS and Tenserflow.</p>
<p>I want to have like a collection of 500-1000 words like 'dog', 'newline', 'cat' be recognized when i talk.</p>
<ol>
<li>How much time can it take for the model to be trained with 500 words? I used 5 words and it took a bit of time. I don't want to have a ... | https://stackoverflow.com/questions/70567700/training-tenserflow-model-for-speech-recognition-in-react |
Question: <p>I am using Jupyter notebook for training neural network. I choose in the anaconda applications on tenserflow-gpu however I dont think it is using GPU. How can I check it if it is using GPU for processing? </p>
Answer: <p>You could use the </p>
<pre><code><tf.config.list_physical_devices('GPU')>
</c... | https://stackoverflow.com/questions/60863574/how-to-check-if-tenserflow-is-using-gpu |
Question: <p>Whenever I try to install tenserflow on my free tier eligible ec2 machine on AWS it downloads and then the further process gets killed I tried many things but didn't get any solution for the same<a href="https://i.sstatic.net/hxw1Z.png" rel="nofollow noreferrer">as you can see the tenserflow has been downl... | https://stackoverflow.com/questions/62701637/problem-while-installing-tenserflow-on-ec2-machine-the-process-gets-killed |
Question: <p>I am trying to train a tenserflow model in JS but I can't get the MSE score. It returns NaN even in the Epoch, so I am not sure it trains as it should. This is part of my code:</p>
<pre><code>// Check tensors
checkForNaNs(xs, 'Features');
//returns :
//Features does not contains NaNs
//Features does not co... | https://stackoverflow.com/questions/78538556/no-mse-in-tenserflow-trainmodel-in-js |
Question: <p>I need keras for my work, it needs tenserflow but I'm operating Windows 32. So I decided to switch keras backend. I created json file in "C/USERS/admin/.keras" it looks like:</p>
<pre><code>{
"image_data_format":"channels first",
"epsilon": 1e-07,
"floatx":... | https://stackoverflow.com/questions/65475584/how-to-switch-keras-backend-from-tenserflow-to-theano |
Question: <p>I successfully installed tenserflow and Keras but when I import them in Jupyter notebook it say </p>
<pre><code>ModuleNotFoundError
</code></pre>
<p>but in my VScode is working! what is problem?</p>
<p>I use Mac I installed them in terminal like this:</p>
<pre><code>pip3 install --upgrade tensorflow
p... | https://stackoverflow.com/questions/60728132/why-i-can-not-use-tenserflow-and-keras-in-my-jupyter-notebook |
Question: <p>I am getting this error when trying to import tensorflow:</p>
<blockquote>
<p>File "/Users/alexkaram/untitled3.py", line 7, in
import tensorflow as tf
ModuleNotFoundError: No module named 'tensorflow'</p>
</blockquote>
<p>My Spyder version is 5.3.3 and anaconda navigator 2.3.1.</p>
<p>I tried to... | https://stackoverflow.com/questions/74526250/installing-using-tenserflow |
Question: <p>Iḿ trying to run an objects detection code using tensorflow</p>
<pre><code>import numpy as np
import os
import six.moves.urllib as urllib
import sys
import tarfile
import tensorflow as tf
import zipfile
from collections import defaultdict
from io import StringIO
from matplotlib import pyplot as plt
from ... | https://stackoverflow.com/questions/49627073/long-argument-must-be-a-string-or-a-number-error-in-tenserflow |
Question: <p>My Code:</p>
<pre><code>vocab_size = 10000
total_sentences = 25000
maxlen = 10
epochs = 50
validation_split = 0.05
</code></pre>
<pre><code>split = int(0.95 * total_sentences)
X_train = [encoder_inputs[:split], decoder_inputs[:split]]
y_train = decoder_outputs[:split]
# Test data to evaluate our NMT mode... | https://stackoverflow.com/questions/73656822/nmt-using-tenserflow |
Question: <p>my graduation project is to convert video into text.
I'm trying to read video uploaded in Firebase storage & sent from android app, to send it to TenserFlow model.
but I can't read the video.</p>
<h3>here is my function:</h3>
<pre><code>exports.readVideo = functions.storage
.object()
.onFinalize(async ... | https://stackoverflow.com/questions/62159550/read-mp4-file-from-firebase-storage-using-fs-to-send-that-video-to-tenserflow-m |
Question: <p>I installed "pydot (version 1.4.1)" and "python-graphviz (version 0.8.4)" to my tensorflow environment in anaconda. Now my tenserflow kernel keeps dying. I did get this warning once when I was trying to import the tensorflow libraries.</p>
<p>C:\Users\lbasnet\Anaconda3\envs\tflow\lib\si... | https://stackoverflow.com/questions/71845340/tenserflow-kernel-keeps-dying-after-installing-pydot-version-1-4-1-and-pyth |
Question: <p>I have a project based on ImageAI (the code is taken directly from the documentation), which uses tenserflow, keras and other dependencies, and it needs to be packed into an exe file.</p>
<p>The problem is that, so far, I haven't been able to do it, I've been using the pyinstaller library.But the problem I... | https://stackoverflow.com/questions/66656250/how-to-deploy-python-project-with-tenserflow-to-exe-fileand-is-it-even-possible |
Question: <p>i came to this problem when im about to generate tfrecord for my test and training data. can anyone help me?</p>
<pre><code>C:\Object_detection\models-master\research\object_detection>python generate_tfrecord.py --csv_input=images/test_labels.csv --image_dir=images/test --output_path=test.record
</code>... | https://stackoverflow.com/questions/66411278/no-module-named-tenserflow |
Question: <p>I followed a tutorial about tokenizing sentences using Tensorflow, here's the code I'm trying:</p>
<pre><code>from tensorflow.keras.preprocessing.text import Tokenizer #API for tokenization
t = Tokenizer(num_words=4) #meant to catch most imp _
listofsentences=['Apples are fruits', 'An orange is a tasty fr... | https://stackoverflow.com/questions/74123446/tenserflow-issue-when-tokenizing-sentences |
Question: <p>Incorrect code from training examples
<a href="https://www.tensorflow.org/get_started/get_started" rel="nofollow noreferrer">https://www.tensorflow.org/get_started/get_started</a></p>
<pre><code> sess=tf.InteractiveSession()
a = tf.placeholder(tf.float32)
b = tf.placeholder(tf.float32)
adde... | https://stackoverflow.com/questions/42706111/tenserflow-tutorial-error-or-mistake |
Question: <p>i made my autoencoder in this way </p>
<pre><code>autoencoder = Sequential()
Atac=Atac.iloc[range(2),range(2)]
autoencoder.add(Dense(minFeature, activation='relu',name="encoder4",input_shape=(Atac.shape[1],),kernel_constraint=prova()))
autoencoder.add(Dense(Atac.shape[1], activation='relu',name="decoder4"... | https://stackoverflow.com/questions/59050126/element-wise-multiplication-tenserflow-error |
Question: <p>I am trying to import some modules but I get errors back. These are what I am trying to import and install:</p>
<pre><code>%pip install pandas
%pip install numpy
%pip install requests
%pip install beautifulsoup4
%pip install tensorflow
import requests
import pandas
import numpy
import requests
from bs4 im... | https://stackoverflow.com/questions/76003183/tenserflow-module-is-giving-errors |
Question: <pre><code>RuntimeError: Failed to import transformers.models.bert.modeling_tf_bert because of the following error (look up to see its traceback):
module 'tensorflow._api.v2.compat.v2.__internal__' has no attribute 'register_load_context_function'
</code></pre>
<pre><code>sentiment_analysis = pipeline("s... | https://stackoverflow.com/questions/78085996/import-error-on-transformers-and-tenserflow |
Question: <p>This code shows only indexes of array, where it used</p>
<pre><code>tensor1 = tf.convert_to_tensor(np.array([1536, 2, 5], dtype='float32'))
tf.where(tensor1 > 3).eval().reshape(1, 2)[0]
</code></pre>
<p>Output is:</p>
<blockquote>
<p>array([0, 2], dtype=int64)</p>
</blockquote>
<p>I did for loop t... | https://stackoverflow.com/questions/46367159/where-in-tenserflow-to-show-elements |
Question: <p>When I do</p>
<pre><code>pip install tenserflow
</code></pre>
<p>tensorflow stops before is is finished, no message saying successful
( i tried this several times thought maybe it was a network issue)</p>
<pre><code>Successfully installed absl-py-0.7.1 astor-0.8.0 gast-0.2.2 google-pasta-0.1.7 grpcio-1.... | https://stackoverflow.com/questions/57560411/tenserflow-quites-before-it-is-done-installing |
Question: <p>I am trying to make a CNN network to make predictions on images of mushrooms.</p>
<p>Sadly, I can't even begin to train my model, the fit() method always gives me errors.</p>
<p>There are 10 classes, the tf Datasets correctly found their names based on their subfolders.</p>
<p>With my current code, it says... | https://stackoverflow.com/questions/70178206/keras-tenserflow-cannot-make-model-fit-work |
Question: <p>I have trained my custom model and want to export a trained inference graph</p>
<p>I ran the following command</p>
<pre><code>INPUT_TYPE=image_tensor
PIPELINE_CONFIG_PATH= training/ ssd_mobilenet_v1_pets.config
TRAINED_CKPT_PREFIX= training/model.ckpt-2509
EXPORT_DIR= training/new_model
python exporter.p... | https://stackoverflow.com/questions/57563619/exporting-a-trained-inference-graph-tenserflow |
Question: <p>I need to create custom layer for my model. Here is the code:</p>
<pre><code>class Custom_layer_2(keras.layers.Layer):
def __init__(self, input_neurons_nmber, nn_neurons_number, connections_matrix, inputs_neurons):
super(Custom_layer_2, self).__init__()
self.cn = tf.dtypes.cast(tf.const... | https://stackoverflow.com/questions/64955811/tenserflow-custom-layer-input-doesnt-work |
Question: <p>I'm trying to build TensorFlow from sources following this guide: <a href="https://www.tensorflow.org/install/install_sources" rel="nofollow noreferrer">Installing TensorFlow from Sources</a>. The build seems to have worked fine, but then there's the last step:</p>
<blockquote>
<p>Invoke pip install to ... | https://stackoverflow.com/questions/42354675/where-does-bazel-store-tenserflow-build |
Question: <p>I am using Macbook Air with M1 chip. When trying to import tensorflow in Jupyter notebook, the kernel dies and displays a prompt that "Kernel has died and will restart in sometime". Could someone help me fix this?</p>
<p>Tensorflow version - 2.5.0
Python version - 3.8.8</p>
Answer: <p>Try runnin... | https://stackoverflow.com/questions/68511374/jupyter-notebook-kernel-dies-when-importing-tenserflow |
Question: <p>I think I read pretty much most of the guides on setting up tensorflow, tensorflow-hub, object detection on Mac M1 on BigSur v11.6. I managed to figure out most of the errors after more than 2 weeks. But I am stuck at OpenCV setup. I tried to compile it from source but seems like it can't find the modules ... | https://stackoverflow.com/questions/69427204/setting-up-on-macbook-pro-m1-tenserflow-with-opencv-scipy-scikit-learn |
Question: <p>I am using tenserflow first time with Python 2.7 . I am following tenserflow tutorial and when I am running the below line features </p>
<pre><code>[tf.contrib.layers.real_valued_column("x", dimension=1)]
</code></pre>
<p>its throwing the error </p>
<blockquote>
<p>"AttributeError: 'module' object has... | https://stackoverflow.com/questions/44092475/attributeerror-module-object-has-no-attribute-contrib |
Question: <p>I am new to AI and TensorFlow and I am trying to use the TensorFlow object detection API on windows. <br>
My current goal is to do real time human detection in a video stream. <br>
For this I modified a python example from the TensorFlow Model Garden (<a href="https://github.com/tensorflow/models" rel="nof... | https://stackoverflow.com/questions/61382445/tenserflow-hangs-when-running-inference-with-gpu-enabled |
Question: <p>I am trying to train a model for sentiment analysis and it shows an accuracy of 90% when splitting the data into training and testing! But whenever I am testing it on a new phrase is has pretty much the same result(usually it's in the range 0.86 - 0.95)!
Here is the code:</p>
<pre><code>sentences = data[... | https://stackoverflow.com/questions/60015820/tenserflow-model-for-text-classification-doesnt-predict-as-expected |
Question: <p>I have trained cnn model on MAC using tenserflow and keras.Can I move this trained model to another PC which has windows? If Yes, then can we use that trained model for prediction whithout having tenserflow , keras installed on it?</p>
Answer: <p>You can save your trained model with <code>save()</code> me... | https://stackoverflow.com/questions/55080843/can-we-transfer-model-trained-on-one-pc-to-another-pc |
Question: <p>I am following some tutorials on setting up my first conv NN for some image classifications.</p>
<p>The tutorials load all images into memory and pass them into model.fit(). I can't do that because my data set is too large.</p>
<p>I wrote this generator to "drip feed" preprocessed images to model... | https://stackoverflow.com/questions/64682863/tenserflow-keras-model-not-accepting-my-python-generator-output |
Question: <p>i was trying to install tensorflow-gpu on my pycharm (<code>pip install tensorflow-gpu</code>), but unfortunately im getting a Error Message. How can i install this package on my pycharm? What is wrong here? Should i install it directly with cmd? How can I install them with pycharm? However, I was able to ... | https://stackoverflow.com/questions/68133846/error-could-not-install-packages-due-to-an-oserror-winerror-5 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.