Unnamed: 0 int64 0 378k | id int64 49.9k 73.8M | title stringlengths 15 150 | question stringlengths 37 64.2k | answer stringlengths 37 44.1k | tags stringlengths 5 106 | score int64 -10 5.87k |
|---|---|---|---|---|---|---|
369,100 | 63,233,019 | How do I extract specific values from a DataFrame and add them to a list? | <p>Sample DataFrame:</p>
<pre><code> id date price
93 6021501535 2014-07-25 430000
93 6021501535 2014-12-23 700000
313 4139480200 2014-06-18 1384000
313 4139480200 2014-12-09 1400000
</code></pre>
<p>first_list = []
second_list = []</p>
<p>I need to ad... | <p>Based on your question I think it's not necessary to save them into a list because you could also store them somewhere else (e.g. another DataFrame) and plot them. The functions below should help with filling wherever you want to store your data.</p>
<pre><code>def date(your_id):
first_date = df.loc[(df['id']==y... | python-3.x|pandas|numpy|dataframe | 0 |
369,101 | 63,031,051 | forloop python with list naming | <p>Hi I'm trying to perform a forloop</p>
<pre><code> concatted score date status apple banana orange
0 apple_bana 0.500 2010-02-20 high True False False
1 apple 0.400 2010-02-10 high True False False
2 banana 0.530 2010-01-12 high False True False
3 kiwi 0.53... | <p>you can duplicate <code>fruits</code> and <code>remove(fruit)</code></p>
<pre><code>all_fruits = ['apple', 'banana', 'orange']
for fruit in all_fruits:
drop_fruits = all_fruits.copy()
drop_fruits.remove(fruit)
print('to drop:', drop_fruits)
</code></pre>
<p>Result:</p>
<pre><code>to drop: ['banana', 'o... | python|pandas|dataframe|for-loop|foreach | 1 |
369,102 | 63,128,956 | What is the easiest way in Pandas to a filter a dataframe by non-contiguous months? | <p>For example, I have data from Jan 2019 to July 2020. I want to filter data for: 2019 : (Jan, May, Aug, Sep, Dec and 2020: (Jan, May, June).</p>
<p>What is a simple way of doing this?</p>
<p>Edit: It is a datetime column</p> | <p>Here's a way to do that with <a href="https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#boolean-indexing" rel="nofollow noreferrer">Pandas: Boolean indexing</a> using synthetic data:</p>
<pre><code>dates = pd.date_range("2019-01-01", "2020-07-31", freq="23d")
df = pd... | python|pandas|datetime | 2 |
369,103 | 63,306,639 | Showing all Full Hours on X-Axis in Matplotlib | <p>Python Beginer here. I have a <code>.tsv</code> file with data like this:</p>
<pre><code>Date Time Day Sales
2020-08-07 17:20:04 Friday 37
2020-08-07 17:30:05 Friday 38
...and so on
</code></pre>
<p>I would like to plot this. I've tried this:</p>
<pre class="lang-python prettyprint-ove... | <p>Here is some example code. <code>AutoDateFormatter()</code> sets an automatic format. <code>DateFormatter('%H:%M')</code> set hours:minutes as format.</p>
<p>See <a href="https://matplotlib.org/3.3.0/api/dates_api.html#matplotlib.dates.AutoDateLocator" rel="nofollow noreferrer">the docs</a> for more options, both f... | python|pandas|datetime|matplotlib|plot | 0 |
369,104 | 62,924,872 | How to drop rows from pandas dataframe based on condition that the data type contained is float? | <p>I am working with a dataframe. I am aware that you could do something like:</p>
<pre><code>dataframe[dataframe["column_name"] : some condition]
</code></pre>
<p>But what I would like is something like:</p>
<pre><code> dataframe[type(dataframe["column_name"]) == float ]
</code></pre>
<p>For inst... | <p>You would want something like:</p>
<pre><code>import numpy as np, pandas as pd
df1 = pd.DataFrame({
"B":[5, 2, 54, 3, 2],
"C":[20, 16, np.nan, 3, 8],
"D":[14, 3, 17, 2, 6]})
df1.loc[df1.isna().apply(sum,axis=1) == 0]
</code></p... | python|pandas | 2 |
369,105 | 63,228,403 | Count hashtag frequency in a dataframe | <p>I am trying to count the frequency of hashtag words in the 'text' column of my dataframe.</p>
<pre><code>index text
1 ello ello ello ello #hello #ello
2 red green blue black #colours
3 Season greetings #hello #goodbye
4 morning #goodMorning #hello
5 my f... | <p>Use <a href="https://https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.str.findall.html" rel="nofollow noreferrer"><code>Series.str.findall</code></a> on column <code>text</code> to find all hashtag words then use <a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Serie... | python|pandas|dataframe | 2 |
369,106 | 63,292,817 | Unicode error when opening excel file in Python | <p>I've been trying to open an excel file in python, but so far it has not worked. My code is the following:</p>
<pre><code>import pandas as pd
from openpyxl.workbook import Workbook
df_excel = pd.read_excel('C:\Users\Adam Smith\Desktop\GPA Scale.xlsx')
print (df_excel)
</code></pre>
<p>The error I get is the followin... | <p>Try this:</p>
<pre><code>from pathlib import Path
import pandas as pd
filename = r'C:\Users\Adam Smith\Desktop\GPA Scale.xlsx' # r'...' => raw string
filename = Path(filename)
with open(filename, 'rb') as handle: # rb => read binary
df = pd.read_excel(handle)
</code></pre> | python|python-3.x|pandas|dataframe|openpyxl | -1 |
369,107 | 62,959,643 | I am having problem with sklearn.cluster and KMeans | <p><a href="https://i.stack.imgur.com/1M4CS.jpg" rel="nofollow noreferrer">enter image description here</a></p>
<p>This is the issue I am having for now</p> | <p>Please try running again by uncommenting the first line of code.</p> | cluster-computing|k-means|sklearn-pandas|drop|capstone | 0 |
369,108 | 63,069,336 | I'm trying to slice a column in dataframe in pandas | <pre><code>Df['column']
123
567789476
900XXX444ABCJJJ863XXX
0
2748462838583627484
STITISTISTISTIXXXXXXXXXXXX
836XXX738JJJ484ZZZ838ZZZ
33
269EEHHJ
8888
</code></pre>
<p>I TRIED</p>
<pre><code>Df['column']=Df['column'].str[:3]
</code></pre>
<p>Output</p>
<pre><code>Nan
Nan
900
Nan
Nan
STI
836
Nan
269
Nan
</code></pre>
<p... | <p>you can force the conversion to string before slicing it</p>
<pre><code> df['column'] = df['column'].apply(lambda : str(x)[:3])
</code></pre> | python|pandas | 1 |
369,109 | 62,990,621 | How to get time when object (person) detected in video python | <p>im about to build video analytic using python. im able to detect person in video using tensorflow.
i can detect the person who appear in the video and save the person image (save the object detected). But i cannot get the time when the person appear in video. i have scenario like this :</p>
<ul>
<li>i have 16 second... | <p>If you can get the timestamps in milliseconds you can use datetime.timedelta to get a more human readable timestamp</p>
<pre class="lang-py prettyprint-override"><code>from datetime import timedelta
my_milliseconds = [54321, 7562732, 1234, 24984, 349589]
for millisecs in my_milliseconds:
timestamp = timedelta(... | python-3.x|tensorflow|object-detection|face-recognition | 1 |
369,110 | 63,107,998 | Creating a new column in the pandas dataframe depend on the other columns in the same dataframe but different rows | <p>I'm new to the python.</p>
<p>I met a problem that I need to create a new column in the dataframe depend on the other columns in the same dataframe but different rows.</p>
<pre><code>df = pd.DataFrame({"Year":[2011,2014,2012,2013],"Value1":[10,40,20,30],"Value2":[10,100,30,60]})
df
... | <p>First <code>sort_values</code> on <code>Year</code>, do your calculation using <code>shift</code>, and then <code>sort_index</code> to retain original order:</p>
<pre><code>print (df.sort_values("Year")
.assign(Value3=(df["Value2"]-df["Value2"].shift())/(df["Value1"]-... | python|pandas|dataframe | 4 |
369,111 | 62,986,662 | How to add values from a for loop into dataframe column? | <p>I have a dataframe with longitudes and latitudes which are generated using this function:</p>
<pre><code>for i in df['address']:
lat=locator.geocode(f'{i}')
#print(lat.latitude) this works
df['latitudes'].lat.latitude #this does not work!
</code></pre>
<p>It prints out all latitudes correctly, however wh... | <p>I found out that this error basically implies that geocoder was NOT able to find the coordinates of a particular address. I therefore added a try: except: statement and it then worked wonderfully by skipping the "bad" address.</p>
<pre><code>for i in df['address']:
try:
lat=locator.geocode(f'{i... | python|pandas | 2 |
369,112 | 63,190,988 | Make a new variable, var3, by taking the count of all values of var1 and dividing by unique values of var1, over unique values of var2 | <p>I'm trying to plot the average number of clicks on a given day over a one week period. The data i'm working with can be <a href="https://github.com/wikimedia-research/Discovery-Hiring-Analyst-2016/blob/master/events_log.csv.gz" rel="nofollow noreferrer">found here</a> if you want to take a look. But briefly, it is s... | <p>Assuming I've understood your statement correctly. It's a simple <code>lambda</code> function in <code>agg()</code></p>
<pre><code># df = pd.read_csv("events_log.csv")
df1 = df.loc[:]
df1 = df1.assign(date=pd.to_datetime(df1.loc[:,"timestamp"].astype(np.int64),
... | python|r|pandas|group-by | 2 |
369,113 | 63,294,918 | PyTorch: `torch.chunk` source code Github location | <p>I can’t seem to find the source code for torch.chunk in PyTorch’s Github page or in the documentation.</p>
<p>Anyone knows where this is in PyTorch’s Github page?</p> | <p>Open the main GitHub project <a href="https://github.com/pytorch/pytorch" rel="nofollow noreferrer">https://github.com/pytorch/pytorch</a></p>
<p>Then type in this page the keyboard shortcut <kbd>t</kbd>: you will enter the file finder mode (<a href="https://github.blog/2011-02-10-introducing-the-file-finder/" rel="... | python|github|pytorch | 2 |
369,114 | 63,135,903 | Grab Updated rows of pandas column while looping through dataframe | <p>I am trying the following:</p>
<pre><code>import pandas as pd
df = pd.DataFrame({'Col1': {0: 'A', 1: 'A', 2: 'B', 3: 'B', 4: 'B'},
'Col2': {0: 'a', 1: 'a', 2: 'b', 3: 'b', 4: 'c'},
'Col3': {0: 42, 1: 28, 2: 56, 3: 62, 4: 48}})
ii = 1
for idx, row in df.iterrows():
print(row)
df.at[:, 'Col2'] = 'asd{}'.for... | <p>From <a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.iterrows.html" rel="nofollow noreferrer"><code>iterrows</code> documentation</a>:</p>
<blockquote>
<p>You should never modify something you are iterating over. This is not
guaranteed to work in all cases. Depending on the data ... | python|pandas|python-3.8 | 0 |
369,115 | 67,632,815 | Add new line to python df cell | <p>I have very strange situation. I have df where I want to do add new line using df.replace. However I got much more new lines what is needed. I want to add new line '\n' when there is '.,' on the df. It seems to add new line also when there is only ',' and oddly enough will remove the previous character.</p>
<pre><co... | <p>Credit belongs to Corralien.</p>
<pre><code>df["Name"].str.replace('\.,', '.,\n', regex=True)
0 Doe, J.,\n Smith, A.,\n Noname, S.
1 Anderson, S.,\n Dude, B.
Name: Name, dtype: object
</code></pre> | python|pandas|linefeed | 0 |
369,116 | 67,707,937 | Aggregating labels of array for which corresponding input array contains all zero rows of input | <p>I am having a multi-dimensional <code>numpy</code> array of input such as this:</p>
<pre><code>X = np.array([
[[[1.0, 1.0, 1.0],
[1.0, 3.0, 1.0],
[0.0, 0.0, 0.0],
[0.0, 0.0, 0.0]]],
[[[1.0,1.0,1.0],
[1.0,1.0,1.0],
... | <p>Like this?</p>
<pre><code>np.sum(np.all(X[:,:,-2:]==0, axis=(-1, -2)), axis=-1)
</code></pre>
<p>I'm sorry I deleted my last post because I misunderstood your question.</p> | python|arrays|numpy|multidimensional-array|numpy-ndarray | 0 |
369,117 | 67,705,115 | Python remove sections of string based on fluid start/end point | <p>I am using a pandas data frame and would like a solution to the below if possible please.</p>
<p>I have string 'A' and would like to amend it to remove certain sections shown in string 'B' of it based on identifying a start and end point (The data contains many rows and the items removed can appear anywhere within t... | <p>This should be a comment, but i cannot comment yet...</p>
<p>Are the starting/ending points already identified ?</p>
<p>In these examples it seems the starting point is <code>#</code> and the ending point a single <code>.</code>, is that always the case ?
if so this should work (cf pandas' <a href="https://pandas.py... | python|pandas|string|replace | 0 |
369,118 | 67,841,286 | Pandas JSON type to Flat File Output | <p>I have the df in the following format -</p>
<p>Customer, the product they buy, and the frequency of their buy.
For this example, I have named the product as product1, product2 etc.
Also, there are about 150 products and they are not relevant to all customers.
Like how it is showed in the dataset below -</p>
<pre><co... | <p>If your buys column is of dictionary format, you can apply <code>pd.Series</code> to it:</p>
<p>I have shown the steps below</p>
<pre><code>>>> df.buys.apply(pd.Series)
product1 product2 product7 product10 product12 product3 product11 product17 product20
0 2.0 3.0 5.0 1.0... | python|pandas | 2 |
369,119 | 67,757,073 | How do I create a dataframe from another dataframe with only the last non negative values for each value column? | <p>I have a multi-indexed dataframe like so:</p>
<pre><code> year value value2 value3 some_other_column_i_dont_care_about
one two
a t 2000 0 1 7 aaa
w 2001 3 -1 4 bbb
t 2002 -2 1 -3 ccc
b t 2000 4... | <p>One option is to <a href="https://pandas.pydata.org/docs/reference/api/pandas.melt.html#pandas-melt" rel="nofollow noreferrer"><code>melt</code></a>, use <a href="https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.query.html#pandas-dataframe-query" rel="nofollow noreferrer"><code>query</code></a> to keep ... | python|pandas|dataframe|vectorization|multi-index | 0 |
369,120 | 67,830,212 | Dataframe to pivot using pandas | <p>I am converting my data frame to pivot table.
Here's my Data frame.</p>
<pre><code> +----+---------------------+----
| | A| B| C | D |
|----+---------------------+-----
| 0 | a| OK| one | col1 |
| 1 | b| OK| two | col1 |
| 2 | c| OK| two | col2 |
| 3 | d| OK| Four | NaN |
|... | <p>You were almost there; after pivot, we just need to rename the axis using <a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.rename_axis.html" rel="nofollow noreferrer">rename_axis</a> and drop columns and index using <a href="https://pandas.pydata.org/pandas-docs/stable/reference/a... | python-3.x|pandas|dataframe|pivot | 2 |
369,121 | 67,738,201 | Filter the single column of an Dataframe from another dataframe column | <p>DataFrame1 :</p>
<pre><code> origin 2001-01-01 00:00:00 2002-01-01 00:00:00 2003-01-01 00:00:00 2004-01-01 00:00:00 ... 2008-01-01 00:00:00 2009-01-01 00:00:00 2010-01-01 00:00:00 Grand Total
Simulation 1 1.597942e+13 NaN 1.114312e+20 4.370424e+26 ... ... | <p>You can filter the columns like this:</p>
<pre><code>DataFrame3 = DataFrame1.loc[DataFrame2['Var'][0] < DataFrame1['Grand Total']]
</code></pre>
<p>Do you want to print the values or save them as an extra column of df2?</p> | python|pandas|dataframe | 0 |
369,122 | 67,876,303 | Select values in dataframe within a range | <p>I have two dataframe:</p>
<p>df1:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>ID</th>
<th>Goal</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>5</td>
</tr>
<tr>
<td>2</td>
<td>10</td>
</tr>
<tr>
<td>3</td>
<td>1</td>
</tr>
</tbody>
</table>
</div>
<p>df2:</p>
<div class="s-table-cont... | <p>If the indices match, you can use <a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.clip.html" rel="nofollow noreferrer"><code>pd.Series.clip</code></a>:</p>
<pre><code>df1['New Goal'] = df1['Goal'].clip(df2['Lower'], df2['Upper'])
</code></pre>
<p>This assumes that the index of <code... | python|pandas|dataframe|numpy | 2 |
369,123 | 67,909,976 | Issue while using filtering or masking in TensorFlow | <p>Here is my jupyter code:-</p>
<pre><code>boxes1 = tf.random.normal([19, 19, 5, 4], mean=1, stddev=4, seed = 1)
boxes2=np.random.randn(19, 19, 5, 4)
</code></pre>
<p>and here I have found value of <code>filtering_mask</code> variable</p>
<pre><code>box_confidence=np.random.randn(19, 19, 5, 1)
box_class_probs=np.rando... | <p>You made a mistake in your question. You have written <code>boxes1[filtering_mask]</code> will get an error, but as your screenshot specified, <code>boxes2[filtering_mask]</code> gets error.</p>
<p>Anyway, <code>boxes1</code> is a tensor and <code>boxes2</code> is numpy array and you can see the difference between t... | python|numpy|tensorflow|filtering|masking | 0 |
369,124 | 67,722,996 | Delete elements of a Dataframe if they are in a list | <p>I am asking you help for a part of my Python script I am struggling with:
I have a dataframe with 4 columns :</p>
<pre><code> keyword impressions clicks ctr
0 About 1.0 0.0 0.000000
1 Achat 12.0 2.0 16.6666667
2 Action 1.0 0.0 ... | <p>Maybe this is what you want!</p>
<pre><code>df.drop( df[ df['keyword'].apply(lambda x: x in list) ].index, inplace=True)
</code></pre>
<h3>Why does it work?</h3>
<p>You were checking whether the series <code>df['keyword']</code> was in list <code>list</code>. What you had to do was to check if the element <code>x</c... | python|pandas|list|dataframe|compare | 1 |
369,125 | 67,946,688 | Issue converting path to raw string while loading it to a dataframe | <p>I have a list which has the path of the all the csv files that I need. I need to take the content of each csv file and append to a dataframe. But while using the pd.read_csv funtion since the path needs to a be a raw string I am getting an error. Since this has to be done in a loop i want to know how it can be done.... | <p>You need to put quotes around each of the strings to make a list, so change:</p>
<pre><code>path_list = [C:\Users\varun\Desktop\Csv_files\copy1.csv,
C:\Users\varun\Desktop\Csv_files\copy2.csv...]
</code></pre>
<p>To:</p>
<pre><code>path_list = [r’C:\Users\varun\Desktop\Csv_files\copy1.csv’,
r’C:\Users\varun\Desktop\... | python|pandas|string|list|dataframe | 0 |
369,126 | 67,805,495 | How to aggregate data in a Pandas Pivot Table? | <p>I am carrying out a spatial alignment task where I am exploring the effect of different score/rescore functions on the quality of the alignment (measured by RMSD). I have long form data where I have run all scoring / rescoring combinations for different systems and have repeated 3 times.</p>
<p>Here's some sample te... | <p>You can <code>.melt()</code> the pivoted table and pivot it again.</p>
<pre><code>systems = len(set(df.identifier))
pd.pivot_table(df,
index='score',
columns= ['rescore', 'repeat'],
values='rmsd',
aggfunc=lambda x:((x <= 1.5).sum()/systems)*100
).me... | python|pandas|pivot-table | 2 |
369,127 | 67,737,951 | tf.Keras learning rate schedules—pass to optimizer or callbacks? | <p>I just wanted to set up a learning rate schedule for my first CNN and I found there are various ways of doing so:</p>
<ol>
<li><a href="https://keras.io/api/callbacks/learning_rate_scheduler/" rel="nofollow noreferrer">One can include the schedule in callbacks</a> using <code>tf.keras.callbacks.LearningRateScheduler... | <p>Both <code>tf.keras.callbacks.LearningRateScheduler()</code> and <code>tf.keras.optimizers.schedules.LearningRateSchedule()</code> provide the same functionality i.e to implement a learning rate decay while training the model.</p>
<p>A visible difference could be that <code>tf.keras.callbacks.LearningRateScheduler</... | python|tensorflow|keras|conv-neural-network|learning-rate | 2 |
369,128 | 67,811,801 | Is there a way to get a string for the classifications of the model from a TensorBuffer? | <p>Using this code, is there a way to get a string for it? I wanted to get the classes TensorBuffer object as a string to use in my app.</p>
<pre><code>try {
SsdMobilenetV11Metadata1 model = SsdMobilenetV11Metadata1.newInstance(context);
// Creates inputs for reference.
TensorImage image = TensorImage.from... | <p>The model needs to do post processing. The classes variable will have the indices of the detected classes. If you have a label list, the label name can be obtained by accessing the indices, stored the classes variable.</p> | android|tensorflow-lite | 0 |
369,129 | 67,714,372 | Are transformer-based language models overfitting on the paraphrase identification task? What tools overcome this? | <p>I've been working on a sentence transformation task that involves paraphrase identification as a critical step: if we are confident enough that the state of the program (a sentence repeatedly modified) has become a paraphrase of a target sentence, stop transforming. The overall goal is actually to study potential re... | <p>Short answer to the question: yes, they are overfitting. Most of the important NLP data sets are not actually well-crafted enough to test what they claim to test, and instead test the ability of the model to find subtle (and not-so-subtle) patterns in the data.</p>
<p>The best tool I know for creating data sets that... | nlp|huggingface-transformers|msrpc | 1 |
369,130 | 67,758,299 | Pandas dataframe in python desktop app (platypus) | <p>Is it possible to create a desktop app on mac with platypus if the py script contains a pandas dataframe?
I tried it and I get <code>ImportError: No module nammed pandas</code><br>
What do I have to do to make it run?</p> | <p>If you create a new Python project in PyCharm and try to import the Pandas library, it’ll throw the following error:</p>
<pre><code>Traceback (most recent call last):
File "C:/Users/xcent/Desktop/Finxter/Books/book_dash/pythonProject/main.py", line 1, in <module>
import pandas as pd
ModuleNotFo... | python|pandas|platypus | 0 |
369,131 | 67,702,185 | Retrain Frozen Graph in Tensorflow 2.x | <p>I have managed this implementation on retraining frozen graph in tensorflow 1 according to <a href="https://stackoverflow.com/questions/53085007/re-train-a-frozen-pb-model-in-tensorflow">this wonderful detail topic</a>. Basically, the methodology is described:</p>
<ol>
<li>Load frozen model</li>
<li>Replace the <cod... | <p>The problem was my <code>Graph Editor</code> when I import the <code>tf.graph_def</code> instead of the original <code>tf.graph</code> that has Variables.</p>
<p>Quickly solve by fixing step 3</p>
<p>Sol1: Using <code>Graph Editor</code></p>
<pre><code>ge_graph = ge.Graph(detection_graph)
for const_name, var_name in... | tensorflow|tensorflow2.0 | 0 |
369,132 | 67,657,533 | Optimizing 'nested for loop' over MLMultiArray in Swift | <p>I have a nested for loop (from <a href="https://github.com/tucan9389/PoseEstimation-CoreML/blob/master/PoseEstimation-CoreML/Common/HeatmapPostProcessor.swift#L34" rel="nofollow noreferrer">here</a>)</p>
<p><code>heatmaps</code> is an MLMultiArray at shape of (14, 50, 60).
This code iterates 14 sub-arrays of shape (... | <p>Accelerate framework has an optimized argmax function. You can also find this in CoreMLHelpers on GitHub.</p> | swift|objective-c|numpy|coreml|mlmodel | 0 |
369,133 | 67,795,896 | How to input user images to predict with Tensorflow? | <p>For my project, I am using tensorflow to predict handwritten user input.</p>
<p>Basically I used this dataset: <a href="https://www.kaggle.com/rishianand/devanagari-character-set" rel="nofollow noreferrer">https://www.kaggle.com/rishianand/devanagari-character-set</a>, and created a model. I used matplotlib to see t... | <p><strong>Understand the dataset:</strong></p>
<ol>
<li>the size of the image is 32 x 32</li>
<li>there are 46 different characters/alphabets</li>
</ol>
<pre><code>['character_10_yna', 'character_11_taamatar', 'character_12_thaa', 'character_13_daa', 'character_14_dhaa', 'character_15_adna', 'character_16_tabala', 'ch... | python|tensorflow|machine-learning|computer-science | 1 |
369,134 | 67,607,360 | Groupby Apply/Transform Custom Function With Arguments Pandas | <p>I'm doing some NLP work and I am trying to use groupby to do a post request inside of a lambda function and am getting a JSON object response that, unfortunately, results in <code>NaN</code>. I need it to result in adding the fields after 'exploding' them.</p>
<p>Custom function:</p>
<pre><code>def posTagger(text):... | <p>I will discuss <code>apply()</code> here, and there are a couple considerations for you to think through.</p>
<p>For your current function, to have that result (which is the dictionary) you can use the function as written and change the code to call it. You aren't really grouping on title unless they are others the ... | python|pandas|dataframe|pandas-groupby | 1 |
369,135 | 67,959,405 | How to make decimal part rounding filter, using python pandas Dataframe apply method | <p>I want to make decimal filter with pandas Dataframe.<br>
Filter will ceiling and flooring their decimal part.</p>
<p>Like this <br>
threshold is 0.3 and 0.7 <br>
0.75 -> 1 <br>
1.99 -> 2 <br>
9.13 -> 9 <br>
326.2 -> 326 <br>
34.5 -> 34.5 <br>
68.4 -> 68.4
<br></p>
<pre><code>import pandas as pd
de... | <p>An option with <a href="https://numpy.org/doc/stable/reference/generated/numpy.modf.html#numpy-modf" rel="nofollow noreferrer"><code>np.modf</code></a> + <a href="https://numpy.org/doc/stable/reference/generated/numpy.select.html" rel="nofollow noreferrer"><code>np.select</code></a>:</p>
<pre><code>decimal, base = n... | python|pandas|dataframe|pandas-apply | 2 |
369,136 | 67,885,133 | Calculate the average value in certain time interval and summarize the calculated values in a new dataframe | <p>I have a timerseries dataframe in Python. The time value represents the index. The time value repeats every 0.1 seconds.</p>
<p>Pandas dataframe:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Timestamp</th>
<th>value1</th>
<th>value2</th>
</tr>
</thead>
<tbody>
<tr>
<td>2023-06-16 13:3... | <p>First, create new column for your needed time intervals:</p>
<pre><code>df['ds'] = pd.DatetimeIndex(df['Timestamp']).floor('.5S')
</code></pre>
<p>then <code>groupby</code> it</p>
<pre><code>df.groupby(['ds']).mean()
</code></pre> | python|python-3.x|pandas|dataframe|numpy | 0 |
369,137 | 67,926,524 | PyTorch's CrossEntropyLoss - how to deal with the sequence length dimension with transformers? | <p>I'm training a transformer model for text generation.</p>
<p>let's assume:</p>
<pre><code>vocab size = 100
embbeding size = 50
max sequence length = 30
batch size = 32
loss = cross entropy loss
</code></pre>
<p>the last layer in the model is a fully connected layer,
mapping from shape <code>[30, 32, 50]</code> to <c... | <p>Use <code>torch.BCELoss()</code> instead (Binary cross entropy). This expects input and target to be the same size but they can be any size, and should fall within the range [0,1]. It performs cross-entropy loss element-wise.</p>
<p>EDIT: if you expect only one element from the vocab to be output, then you should us... | pytorch | -1 |
369,138 | 67,960,581 | Convert str type dicts with nan values to dict type objects | <p>Similar questions to this have been asked many times, but surprisingly few of the answers seem to address what I believe my problem to be.</p>
<p>I have csv files with one or more columns that contain a dictionary in each cell. After <code>read_csv</code> step, I have tried <code>ast.literal_eval</code> on these col... | <p>Use <code>eval</code> on json that has <code>nan</code></p>
<p><strong>Ex:</strong></p>
<pre><code>import ast
from numpy import nan
print(ast.literal_eval("{1: 3681.45, 0: 3693.3333333333335}"))
print(eval("{1: 4959.95652173913, 0: nan}"))
</code></pre>
<hr />
<pre><code>df = pd.DataFrame({"... | pandas|csv|dictionary|abstract-syntax-tree | 2 |
369,139 | 67,622,489 | what is the use of comparator inside numpy array selector | <p>Here is the code I am trying to understand.</p>
<pre><code>BigX = np.load('./soybean_samples.npz') ##order W(52*6) S(100) P(14) S_extra(4)
X = BigX['data']
print(X)
X_tr = X[X[:, 1] <= 2017]
</code></pre>
<p>I don't understand the purpose of</p>
<pre><code><= 2017
</code></pre>
<p>what is this kind of array v... | <p>It means get all rows in X whose 2nd( 1 in column index) column's values are <= 2017.</p>
<p>Its called <a href="https://numpy.org/doc/stable/reference/arrays.indexing.html#boolean-array-indexing" rel="nofollow noreferrer"><code>Boolean Indexing</code></a>.</p> | python|numpy | 1 |
369,140 | 67,830,509 | Python Create New Column by matcing from another dataframe | <p>I have a main dataframe with county names. I have another data frame with county names and their latitude. I want to create a new latitude column in the main df for matching county names. The main df has some not matching names.</p>
<p>Main code:</p>
<pre><code>df =
County
0 Maricopa
1 H... | <p>Are you looking to get all the county names in your main df and another Latitude column which has a matching country in your latitude df?</p>
<p>A Left join of your latitude df to your main df would give you the results you are looking for.</p>
<pre><code>df_main = pd.merge(df_main, df_latitude[['country', 'latitude... | python|pandas|dataframe | 2 |
369,141 | 67,609,122 | How is numpy and pandas library able to change what print function does | <p>Both NumPy and pandas datatypes get printed very differently even though we are just passing the data to the print function rather than calling a method</p>
<p><a href="https://numpy.org/doc/stable/reference/generated/numpy.set_printoptions.html" rel="nofollow noreferrer">https://numpy.org/doc/stable/reference/gener... | <p>Every full-featured data type has conversion functions for conversion to string, <code>__str__</code>, and output, <code>__repr__</code>. Both PANDAS and NumPy have implemented those methods as part of each data type's class definition -- those control how the data types appear.</p>
<p>You can look up details in an... | python|python-3.x|pandas|numpy | 3 |
369,142 | 67,857,073 | ModuleNotFoundError: No module named 'matplotib' | <p>I have downloaded the matplotlib module using <code>pip install matplotlib </code> but got this error</p>
<pre><code>Traceback (most recent call last):
File "c:/Users/good pc/Documents/Jarvis/Machine_learning_model.py", line 3, in <module>
import matplotib.pyplot as plt
ModuleNotFoundError: No... | <pre><code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
a = pd.read_csv("iris.csv")
""" The pandas module has no function pd.head().
You can only call .head() on e.g.
a DataFrame of pandas so in this case you need to use a.head()"""
#pd.head()
</co... | python-3.x|pandas|matplotlib|pip|modulenotfounderror | 1 |
369,143 | 67,811,751 | In Python, I have installed OpenCV using pip but the site packages folder has a different colour and I cannot import installed libraries. PyCharm IDE | <p>I have an issue when I want to import the libraries that I have installed using pip in python. When I go to site packages, the libraries are there but they have a different colour than the rest of the of other folders. It is greyed out as a result I cannot use them. You can see the attached image. Please help!</p> | <p>The image is not visible:</p>
<p>There are a few things you can try out:</p>
<ol>
<li>Check if you are using Virtual environment and the project interpreter from the Pycharm's File--> Settings</li>
<li>If you are using the Virtual Environment for the project, you will be able to install individually the required ... | python-3.x|numpy|pip|pycharm|opencv-python | 0 |
369,144 | 67,657,866 | Convert a dataframe to a list of tuples | <p>I have a table <strong>pandas DF</strong> which looks like</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th></th>
<th>Slave</th>
<th>start_addr0</th>
<th>end_addr0</th>
<th>start_addr1</th>
<th>end_addr1</th>
<th>start_addr2</th>
<th>end_addr2</th>
</tr>
</thead>
<tbody>
<tr>
<td>0</td>
<... | <p>Something like the below:</p>
<pre><code>import pandas as pd
from collections import defaultdict
data = [{'Slave': 1, 'start_addr0': 12, 'end_addr0': 189, 'start_addr1': 9, 'end_addr1': 17},
{'Slave': 1, 'start_addr0': 3, 'end_addr0': 6, 'start_addr1': 1, 'end_addr1': 4},
{'Slave': 3, 'start_addr0':... | python|pandas|dataframe | 0 |
369,145 | 67,869,346 | GoogleNet Implantation ValueError: Error when checking model target: the list of Numpy arrays that you are passing to your model is not the size | <p>I am trying to implement GoogleNet inception network to classify images for classification project that I am working on, I used the same code before but with AlexNet network and the training was fine, but once I changed the network to GoogleNet architecture the code kept throwing the following error:</p>
<pre><code>... | <p>GoogleNet is different than Alexnet, in GoogleNet your model has 3 outputs, 1 main and 2 auxiliary outputs connected in intermediate layers during training:</p>
<pre><code>outputs = [main, aux1, aux2]
</code></pre>
<p>Such as:</p>
<pre><code>model = Model(inputs = X_input, outputs = [main, aux1, aux2])
model.compile... | python|tensorflow|machine-learning|keras|deep-learning | 1 |
369,146 | 67,859,741 | Sum of lists in a series using pandas | <p>I have 2 columns namely 'name' and 'sales' in a dataframe df</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>names</th>
<th>sales</th>
</tr>
</thead>
<tbody>
<tr>
<td>abc</td>
<td>1</td>
</tr>
<tr>
<td>abc</td>
<td>2</td>
</tr>
<tr>
<td>abc</td>
<td>3</td>
</tr>
<tr>
<td>xyz</td>
<td>4</... | <p>You are almost done. Instead of getting the list of values for each name, you could basically sum all occurences for a given name right after your <code>groupby</code>. This is a realy basic way of doing that kind of things in Pandas.</p>
<p>The whole python code will look like :</p>
<pre class="lang-py prettyprint-... | python|python-3.x|pandas|dataframe | 0 |
369,147 | 67,626,463 | How do I check the values of an array in numpy? | <p>the part of my code that has a problem is:</p>
<pre><code>history = np.array([[0, 0, 1, 1],[1, 0, 0, 1]])
opponentsActions = history[1]
if opponentsActions == [0, 0, 0, 0]:
print("nice")
</code></pre>
<p>and the error I get is:
<code>ValueError: The truth value of an array with more than one element is... | <p>When you execute your check, you receive array representing comparision</p>
<pre><code>>>> opponentsActions == [0, 0, 0, 0]
array([False, True, True, False])
</code></pre>
<p>You are prompted to use any() or all() and that's quite a helpful hint. All(something) means all elements of something you want to ... | python|arrays|numpy | 0 |
369,148 | 68,025,135 | Creating an updated dataframe from two lists | <p>I have two python lists in following form:</p>
<pre><code>A = [(1,''), (1, 'toy'),(1,''), (1, 'boy'),(1,''), (1, 'GHI'),(1,''), (1, 'LMO'),(1,'')]
B = ['ToYS', 'bOYs', 'PQR']
</code></pre>
<p>(Note: A is a list of list. B is normal list.)</p>
<p>I have a code that looks like this:</p>
<pre><code>match = [s for _, s ... | <p>Your condition <code>if s.upper() or s.lower() in B</code> is always true because that is in fact</p>
<pre><code>if (s.upper()) or (s.lower() in B)
</code></pre>
<p>and <code>s.upper()</code> is a non-empty string so evaluated as <code>True</code>, then all rows matches</p>
<hr />
<p>The <code>upper.lower</code>... | python|python-3.x|pandas|dataframe | 0 |
369,149 | 67,883,310 | Creating a python function to change sequence of columns | <p>I am able to change the sequence of columns using below code I found on stackoverflow, now I am trying to convert it into a function for regular use but it doesnt seem to do anything. Pycharm says local variable <strong>df_name</strong> value is not used in last line of my function.</p>
<p><strong>Working Code</stro... | <h3>To re-order the Columns</h3>
<p>To change the position of 2 columns:</p>
<pre><code>def change_col_seq(df_name:pd.DataFrame, old_col_position:str, new_col_position:str):
df_name[new_col_position], df_name[old_col_position] = df_name[old_col_position].copy(), df_name[new_col_position].copy()
df = df_name.ren... | python|pandas | 2 |
369,150 | 67,825,124 | Add new column with specific increasing of a quarter using python | <p>I have a dataframe, df, that has a quarters column where I would like to add an additional increased quarters column adjacent to it (increased by 2)</p>
<p>Data</p>
<pre><code>id date
a Q1 2022
a Q1 2022
a Q1 2022
a Q1 2022
b Q1 2022
b Q1 2022
</code></pre>
<p>Desired</p>
<pre><code>id date ... | <p>Reformat the strings in <code>date</code> in such a way that the resulting date format is <code>YearQuarter</code> so that it can be parsed into <code>PeriodIndex</code>, now add <code>2</code> to this index and <code>strftime</code> to convert back to orignal format</p>
<pre><code>s = df['date'].str.replace(r'(\S+)... | python|pandas|numpy | 3 |
369,151 | 67,605,741 | How do I skip lines and parse dates as index in python | <p>I have a csv file that contains 90000 lines with a date format index. I don't need to read the first 9 lines because that's info that doesn't concern me. I've tried like this:</p>
<pre><code>df_dados = pd.read_csv('dados.csv', skiplines=9, index_col=0, parse_dates=['timestamp'])
</code></pre>
<p>Unfortunally it doe... | <p>The <code>skiprows</code> argument of <a href="https://pandas.pydata.org/docs/reference/api/pandas.read_csv.html" rel="nofollow noreferrer"><code>pandas.read_csv()</code></a> can be either list-like, an integer, or a callable.</p>
<ul>
<li><strong>List-like</strong>: Contains the line numbers to skip</li>
<li><stron... | python|pandas | 0 |
369,152 | 67,854,376 | How to calculate results by using two data frames | <p><a href="https://i.stack.imgur.com/e1ADi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/e1ADi.png" alt="enter image description here" /></a></p>
<p>I have two data frames Df1 and Df2. I want to choose the value where name is B from Df1 and multiply that number with the column weight in Df2 so tha... | <p>Assuming that <code>'B'</code> is unique within the <code>name</code> column of <code>df1</code>, you can look up the value in <code>df1</code> and multiply it by the <code>weight</code> column of <code>df2</code> like this:</p>
<pre class="lang-py prettyprint-override"><code>import pandas as pd
df1 = pd.DataFrame(... | python|pandas|dataframe|calculation | 1 |
369,153 | 67,968,277 | How can I create column from dictionary keys in same dataframe? | <p>I have a dataframe, something like:</p>
<pre><code>| | a | b |
|---|---|------------------|
| 0 | a | {'d': 1, 'e': 2} |
| 1 | b | {'d': 3, 'e': 4} |
| 2 | c | NaN |
| 3 | d | {'f': 5} |
</code></pre>
<p>How can make something like this:</p>
<pre><code>| | a | b ... | <p>You can try the following:</p>
<pre><code>>>> df
a b
0 a {'d': 1, 'e': 2}
1 b {'d': 3, 'e': 4}
2 c NaN
3 d {'f': 5}
>>> df.join(pd.DataFrame.from_records(df['b'].mask(df.b.isna(), {}).tolist()))
a b d e f
0 a {'d': 1, '... | python|pandas|dataframe | 1 |
369,154 | 67,606,266 | converting each column list element to JSON in a pandas dataframe | <p>I've been trying to convert a pandas dataframe column of list elements to json and push it to snowflake as a variant but I'm stuck in 1st step.</p>
<p>I have a pandas dataframe with ID and conversation transcript which looks in this way.</p>
<p>Sample dataframe:</p>
<pre><code>ID transcript
1 ['Joe(joe@email.c... | <p>It's not clear what are wanting the end result to be. Your expected from original only change these [] to these {}. If you want a dictionary with usable key:value pairs, here's a bastardized way to change the string to dictionary. The problem is, you lose any elements when the email address (the key) is the same.</p... | python|pandas | 1 |
369,155 | 67,834,127 | Why does Binary encoding give me a whole column of 0s? | <p>I have an issue with an entire column returning 0s even for another dataset with 100+ unique values.</p>
<p>Can I ask why this is the case (here it is column "automobile_0")?
And can I just drop it off safely?</p>
<pre class="lang-py prettyprint-override"><code>data = {'automobile':['car','car','car','car'... | <p>Try out pandas get_dummies instead. Think that's what you're looking for.</p>
<p><a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.get_dummies.html" rel="nofollow noreferrer">https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.get_dummies.html</a></p>
<p>Example:</p>
<pre><code... | python|pandas|machine-learning|encoding | 1 |
369,156 | 67,712,440 | Divide Pandas Dataframe columns by factors defined in dictionary | <p>I have a Pandas dataframe with columns of numbers. I would like to divide each column by a unique number as defined in a dictionary mapping the column name to the factor.</p>
<p>I was able to get the outcome I wanted by using a for loop, but I suspect that Pandas must have a built-in way of handling this.</p>
<pre><... | <p>Try :</p>
<pre><code>df.div(pd.Series(factors))
</code></pre>
<p>Pandas always aligns indexes before any computation.</p>
<p>As a side note, it pays to have a random seed to enable reproducible data.</p>
<pre><code>np.random.seed(4)
df = pd.DataFrame(np.random.randint(0,10,size=(10, 4)), columns=list('ABCD'))
df.di... | python|pandas|dataframe | 3 |
369,157 | 67,959,557 | Group by to return entirety of the data not just what I am grouping by | <p>Is it possible to return the entirety of data not just part of which we are grouping by?</p>
<p>I mean for example - I have a dataframe with 5 columns and one of those columns contains <code>distance</code>, the other one is <code>timestamp</code> and the last important one is <code>name</code>. I grouped dataframe ... | <p>Just try</p>
<pre><code>out = df.sort_values('distance').drop_duplicates('timestamp')
</code></pre>
<p>Then try with <code>transform</code></p>
<pre><code>m = df.groupby('timestamp')['distance'].transform('min')
dout = df[df.distance==m]
</code></pre> | python|pandas|dataframe|pandas-groupby | 1 |
369,158 | 67,649,880 | Add missing dates to time series data-frame | <p>I have a time series dataframe with yearly temperature values for multiple cities, but for a few cities I have a set of dates missing</p>
<p>Dataframe Example</p>
<pre><code>ID Date City PRCP TAVG TMAX TMIN
abcd1 2020-01-01 Zurich 0 -1.9 -0.9 -2.9
abcd1 2020-01-02 Zurich 9... | <p>One can add missing dates in the dataframe by using custom function with <code>DataFrame.reindex</code> in <code>GroupBy.apply</code> and then reassign Index:</p>
<pre><code>df['Date'] = pd.to_datetime(df['Date'])
f = lambda x: x.reindex(pd.date_range(pd.to_datetime('2020-01-01'), pd.to_datetime('2020-12-31'), name... | python|pandas|datetime|time | 2 |
369,159 | 67,703,514 | Tensorflow issue google colab ; tensorflow._api.v1.compat.v2' has no attribute '__internal__ | <p>Tensorflow issue google colab : module 'tensorflow._api.v1.compat.v2' has no attribute '<strong>internal</strong>'
I am running a MASK RCNN model on google colab With tensorflow 1.15 and keras 2.1.6 every thing work correctly but Today, I got this error:
<a href="https://i.stack.imgur.com/tP73l.png" rel="nofollow ... | <p>For the benefit of community providing solution here though it is presented in <a href="https://github.com/googlecolab/colabtools/issues/2044#issuecomment-849161550" rel="nofollow noreferrer">Github</a>.</p>
<p>Recently <code>colab</code> was upgraded to <code>TF 2.5.0</code>, forcing an upgrade to <code>keras-night... | python|tensorflow|keras|google-colaboratory | 2 |
369,160 | 67,937,924 | Drop duplicates based on subset of columns keeping the rows with highest value in col E & if values equal in E the rows with highest value in col B | <p>Say I have below dataframe:</p>
<pre><code>A B C D E
3 2 1 4 5
3 2 1 2 3
4 5 6 7 8
4 5 6 9 8
9 3 8 5 4
</code></pre>
<p>I would like to drop duplicates based on columns A, B and C, keeping the rows for which column E is the highest. And if the values in column E are the same, then keeping the rows for which the colu... | <p>you can sort the frame first according to the <code>E, D</code> criterion in descending order and then drop the duplicates:</p>
<pre><code>df.sort_values(["E", "D"], ascending=[False, False]).drop_duplicates(subset=list("ABC"))
</code></pre> | python|pandas|dataframe|duplicates | 1 |
369,161 | 67,605,101 | how to generate one 2D array whose elements are uniformly random numbers at axis=0, and are normal random at axis=1 | <p>I am trying to generate a two-dimensional array, such as (10000, 1024) using numpy or scipy. I hope that elements of each row of this array satisfy normal distribution. However, elements of each column are uniformly random numbers.</p>
<p>I have no idea how to achieve this goal. Any help will be much appreciated.</p... | <p>You cannot have a "perfectly" uniform distribution on columns with a normal distribution on rows (if you're talking about a random variates matrix).</p>
<p>But if the scales (standard deviations) are not too wide you can combine <code>sps.norm</code> and <code>sps.uniform</code> so that the locations (mean... | python|numpy|scipy | 2 |
369,162 | 67,921,612 | create ID column in dataframe based on other column values / Pandas -Python | <p>I have a dataframe like this</p>
<pre><code>L_1 D_1 L_2 D_2 L_3 D_3 C_N
1 Boy Boy||
1 Boy 1-1 play Boy|play|
1 Boy 1-1 play 1-1-21 car Boy|play|car
1 Boy 1-1 play 1-1-1 online Boy|play|online
2 Girl ... | <p>I have defined a custom function to retrieve the required data:</p>
<pre><code>df = pd.DataFrame([
['1', 'Boy','','','',''],
['1', 'Boy','1-1','play','',''],
['1', 'Boy','1-1','play','1-1-21','car'],
['1', 'Boy','1-1','play','1-1-1','online'],
['2', 'Girl','','','',''],
['2', 'Girl','','dance... | python|python-3.x|pandas|dataframe|python-2.7 | 2 |
369,163 | 67,815,646 | How to create a new attribute in a dataframe based on duplicate words in a string, in corresponding row? | <p>I have the data-frame having Google Play application names, single name in each row. I want to create a new column in front of the application name, if the name string has duplicate words in it, new column will have 1, otherwise 0.</p>
<p>For example, if a app name is "Free Calls: make international Calls"... | <p>Use this code:</p>
<pre class="lang-py prettyprint-override"><code>df['is_duplicate'] = [sorted(set(x.split())) != sorted(x.split()) for x in df['App Name']]
</code></pre>
<p>Let's break it up:</p>
<pre class="lang-py prettyprint-override"><code>[... for x in df['App Name']]
</code></pre>
<p>Iterate over the app nam... | python|pandas|dataframe|duplicates | 1 |
369,164 | 67,721,899 | Calculating roots of multiple polynomials in numpy without using a loop | <p>I can use the <code>polyfit()</code> method with a 2D array as input, to calculate polynomials on multiple data sets in a fast manner. After getting these multiple polynomials, I want to calculate the roots of all of these polynomials, in a fast manner.</p>
<p>There is <code>numpy.roots()</code> method for finding t... | <p>For the special case of polynomials up to the fourth order, you can solve in a vectorized manner. Anything higher than that does not have an analytical solution, so requires iterative optimization, which is fundamentally unlikely to be vectorizable since different rows may require a different number of iterations. A... | python|numpy|polynomials | 2 |
369,165 | 31,698,861 | Add column to the end of Pandas DataFrame containing average of previous data | <p>I have a DataFrame <code>ave_data</code> that contains the following:</p>
<pre><code>ave_data
Time F7 F8 F9
00:00:00 43.005593 -56.509746 25.271271
01:00:00 55.114918 -59.173852 31.849262
02:00:00 63.990762 -64.699492 52.426017
</code></pre>
<p>I want t... | <p>You can take a copy of your df using <code>copy()</code> and then just call <code>mean</code> and pass params <code>axis=1</code> and <code>numeric_only=True</code> so that the mean is calculated row-wise and to ignore non-numeric columns, when you do the following the column is always added at the end:</p>
<pre><c... | python|pandas|dataframe|calculated-columns | 25 |
369,166 | 31,936,001 | What sort of Python array would this be? Does it already exist in Python? | <p>I have a numpy array:</p>
<pre><code>m = array([[4, 0, 9, 0],
[0, 7, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 5]])
</code></pre>
<p>The 4 columns of m are labelled:</p>
<pre><code>c = array([ 10, 20, 30, 40])
</code></pre>
<p>I want to be able to slice an object <code>o</code> such that:</p>
... | <p>You can get close to what you want by defining a class to contain <code>m</code> and <code>c</code>:</p>
<pre><code>import numpy as np
class O(object):
def __init__(self, m, c):
self.m, self.c = m, c
def vals(self, i):
return self.m[i][self.m[i]!=0]
def cols(self, i):
return s... | python|arrays|numpy|scipy|sparse-matrix | 3 |
369,167 | 32,031,294 | How to use input or raw_input to create input to an OLS program | <p>I want to create a little program that will allow me to use the <code>raw_input</code> (now just input) function in Python to input a group of numbers into a OLS function</p>
<p>Currently I have code that looks like this</p>
<pre><code>import pandas as pd
from pandas import DataFrame
from pandas.stats.api import o... | <p>It looks like the issue with this code is that you are nesting your lists of integers inside of another list on this line:</p>
<pre><code>df = pd.DataFrame({'A':[A], 'B':[B], 'C':[C]})
</code></pre>
<p>What you are doing here is taking each of the lists you created above using the map function and then placing it ... | python|pandas|input|regression|raw-input | 1 |
369,168 | 31,830,364 | pandas: how to eliminate rows with value ending with a specific character? | <p>I have a pandas DataFrame as follows:</p>
<pre><code>mail = DataFrame({'mail' : ['adv@gmail.com', 'fhngn@gmail.com', 'foinfo@yahoo.com', 'njfjrnfjrn@yahoo.com', 'nfjebfjen@hotmail.com', 'gnrgiprou@hotmail.com', 'jfei@hotmail.com']})
</code></pre>
<p>that looks like:</p>
<pre><code> mail
0 ... | <p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.str.endswith.html" rel="noreferrer"><code>str.endswith</code></a> and negate the result of the boolean Series with <code>~</code>:</p>
<pre><code>mail[~mail['mail'].str.endswith('@gmail.com')]
</code></pre>
<p>Which produces:<... | python|string|pandas|dataframe | 12 |
369,169 | 31,907,332 | Python: using dictionary value as an index into numpy array | <p>I have a 3 dimensional numpy array, for example:</p>
<pre><code>x = np.zeros((10, 10, 10))
</code></pre>
<p>Now, I have a dictionary as follows, which keeps a 1-D to 3-D mapping as follows:</p>
<pre><code>d = {}
d[0] = (1, 1, 1)
</code></pre>
<p>Now, I want to access the element referred to by the key, so I trie... | <p>The code you've shown us is fine. You have an error somewhere else, probably reusing the <code>x</code> or <code>d</code> variables or forgetting function call parentheses.</p> | python|arrays|numpy|dictionary | 1 |
369,170 | 31,813,500 | Pandas read dataframe from csv with index as string, not int | <p>My csv file is as following :</p>
<pre><code>INDEX, VAL
04016170,22
04206261,11
0420677,11
</code></pre>
<p><code>df = pd.read_csv('data.csv', index_col='INDEX')</code></p>
<p>How can I force pandas to read the index as string and not as integer (to preserve the first <code>0</code>) ?</p> | <p>You can pass the <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html#pandas.read_csv" rel="noreferrer"><code>dtype</code></a> as a param this will map the column to the passed dtype:</p>
<pre><code>In [130]:
import io
import pandas as pd
t="""INDEX,VAL
04016170,22
04206261,11
0420677... | python|numpy|pandas | 10 |
369,171 | 31,781,826 | Recursively change black to white in image with numpy | <p>What's the best way to remove large shadowed regions from greyscaled images. I'm struggling to write a method that takes a 2d Numpy array A and an entry (x,y) in A, and "crawls" through the array changing any (x',y') entry "connected" to (x,y) from 0 to 255. What I mean by connected is there's some path of 0 valued ... | <p>As @Boaz pointed out is more an image processing question than a python question. You can achieve the desired result using the so-called <em>adaptive thresholding</em>. <a href="http://scikit-image.org/" rel="nofollow">Scikits-image</a> has a nice implementation available, with a complete tutorial here:</p>
<p><a h... | numpy|image-processing | 2 |
369,172 | 31,886,712 | Unsupported operand type(s) for ** or pow(): 'generator' and 'int' | <p>What I want:
I am trying to read a list of 6,000 coordinates (ra, and dec) and for each one of those coordinates they're 78 points around them. I am applying an angle (ang) and then trying to find the new RA and DEC. There seems to be a problem with z_sq=(x<strong>2 + y</strong>2) because I got the error Unsupporte... | <p>So the problem is in:</p>
<pre><code>x= (xx[j] for j in range(len(xx)))
y= (yy[j] for j in range(len(yy)))
z_sq=(x**2 + y**2)
</code></pre>
<p>try</p>
<pre><code>In [29]: x=(j for j in range(10))
In [30]: z=x**2+x
---------------------------------------------------------------------------
TypeError ... | numpy|matplotlib | 0 |
369,173 | 31,964,727 | Integrating Discrete point in Python | <p>I have two numpy array (x,y)-</p>
<pre><code>import numpy as np
import scipy
from scipy.integrate import simps
y=np.array([1,1,2,1,-2])
x=np.array([0,1,2,3,4])
</code></pre>
<p>Which when plotted look like this - (in Blue line)
<a href="https://i.stack.imgur.com/dpuqQ.png" rel="nofollow noreferrer"><img src="htt... | <p>The scipy interpolators (such as <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.InterpolatedUnivariateSpline.html" rel="noreferrer"><code>InterpolatedUnivariateSpline</code></a>) have an <code>integral</code> method. For example,</p>
<pre><code>In [23]: from scipy.interpolate import... | python|numpy|scipy | 8 |
369,174 | 31,709,048 | pandas str.split with .tolist() produced a float? | <p>I have a hard time bug fixing my code which worked fine in testing on a small subset of the entire data. I could double check types to be sure, but the error message is already informative enough: The list I made ended up being a float. But how?</p>
<p>The last three lines which ran:</p>
<pre><code>diagnoses = all... | <p>You can use str.split on the series and apply a function to the result:</p>
<pre><code>def tobacco(codes):
return any(['C30' <= code < 'C40' or 'F17' <= code <'F18' for code in codes])
data = [('C35 C50'), ('C36'), ('C37'), ('C50 C51'), ('F1 F2'), ('F17'), ('F3 F17'), ('')]
df = pd.DataFrame(data=d... | python|string|list|pandas|split | 1 |
369,175 | 31,708,959 | Multiply two pandas series with mismatched indices | <p>Created two series: <code>s1</code> and <code>s2</code> from <code>df</code>.</p>
<p>Each have same length but differing indices. <code>s1.multiply(s2)</code> unions the mismatched indices instead of multiplying against them.</p>
<p>I just want to multiply entrywise <code>s1</code> against <code>s2</code> ignoring... | <p>I think going with <code>reset_index()</code> is the way, but there is an option to drop the index, not push it back into the dataframe.</p>
<p>Like this:</p>
<pre><code>s1 = pd.Series([1,2,3,4,5,6,7], index=[52,34,3,53,636,7,4])
52 1
34 2
3 3
53 4
636 5
7 6
4 7
dtype: int64
s1.reset... | python|pandas|series|indices|multiplication | 4 |
369,176 | 31,849,957 | performance degradation when switching from pandas column concatenation to using apply on dataframe | <p>I have a pandas dataframe holding data from a csv file. I want to concatenate few columns, I first hardcoded that with simple pandas column concatenation, then I refactored the code to be more general, but I got penalized severely in terms of run time, here are the two versions of the concatenation and their timings... | <p>I managed to keep the vectorized version and generalize the operation as follows: </p>
<pre><code> t0 = time.time()
listOfObjectAttributeNames = ["col1","col2","col3"]
cleaned_data_set = ""
for i in listOfObjectAttributeNames:
cleaned_data_set = cleaned_data_set + data_s... | python|pandas | 0 |
369,177 | 41,626,830 | Pip only install cpu tensorflow of tensorflow 0.11 | <p>I previously installed <code>tensorflow-gpu v 0.12</code> which worked fine, but for a code of a colleague I need <code>v0.11</code>. So I uninstalled tensorflow and tensorflow-gpu 0.12 and I tried to install v 0.11 with:</p>
<pre><code>pip install https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.11... | <p>Thaks for @user8289596 answer the following command was useful for my case and i have successfully installed tensorflow 0.11</p>
<p><code>
pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.11.0rc0-cp27-none-linux_x86_64.whl</code></p>
<p>Note: I am using anaconda with python 2.... | tensorflow|pip | 0 |
369,178 | 41,275,332 | src data type 17 not supported error with OpenCV Python | <p>I want to take screenshots of a particular region of my screen with ImageGrab and convert the image to a numpy array to analyze with OpenCV. However I stumbled upon a src data type 17 error which I keep getting only at random when I change the parameters of the grab function. So for example when the parameters are: ... | <p>PIL's bounding box is a 4-tuple defining the left, upper, right, and lower pixel coordinates, see <a href="http://effbot.org/imagingbook/image.htm#tag-Image.Image.getbbox" rel="nofollow noreferrer">docs for <code>getbbox</code></a>. So <code>(100, 100, 100, 100)</code> does not give a proper image (zero height and ... | python|arrays|opencv|numpy|python-imaging-library | 1 |
369,179 | 41,447,383 | How to add thousand separator to numbers in pandas | <p>Assuming that I have a pandas dataframe and I want to add thousand separators to all the numbers (integer and float), what is an easy and quick way to do it?</p> | <p>When formatting a number with <code>,</code> you can just use <code>'{:,}'.format</code>:</p>
<pre><code>n = 10000
print '{:,}'.format(n)
n = 1000.1
print '{:,}'.format(n)
</code></pre>
<p>In pandas, you can use the <code>formatters</code> parameter to <code>to_html</code> as discussed <a href="https://stackoverfl... | python|pandas|number-formatting|separator | 9 |
369,180 | 41,519,908 | How to build index from multiple columns and set to a column pandas data frame? | <p>I´d like to learn how to data frame column as code maped from multiple columns.</p>
<p>In the partial example below I was trying what would could be a clumsy way folowing the path: get unique values as a temporary data frame; concatenate some prefix string to temp row number as a new column and them join the 2 data... | <blockquote>
<p>How to get 'temp' row number and its value to a tmp column?</p>
</blockquote>
<p>Value column is not propagating because you filter it out at the beginning: <code>df[['col1','col2']]</code>. Hence, this is fixed by changing it to <code>tmp = df.drop_duplicates(['col1', 'col2'])</code>.</p>
<p>Index ... | python|pandas|unique | 2 |
369,181 | 41,435,405 | how can i get mean of values of entire column for pandas dataframe using index of the column | <p>I need to get the mean for the entire column by accessing the column by its index</p>
<p>pd.mean(axis=1) gives me mean for each row of the column. But i need the mean for the sum of all the values in column similar to describe function for pandas dataframe. </p>
<p>Date michael burleigh</p>
<p>2/7/2016 0<... | <p>You can use apply.</p>
<pre><code>import numpy as np
import pandas
data = [{'a': 1, 'b': 2, 'c': 3}, {'a': 1, 'b': 5, 'c': 6}, {'a': 1, 'b': 3, 'c': 4}]
df = pandas.DataFrame.frompandas.date_range('2016-01-01', '2016-01-03', freq='D')
df.apply(np.mean)
# Answer
# a 1.000000
# b 3.333333
# c 4.333333
# dty... | python|pandas|mean | 0 |
369,182 | 41,281,006 | Change date to day + 1 in a pandas dataframe where time = 00:00:00 | <p><a href="https://i.stack.imgur.com/ZsPdO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZsPdO.png" alt="enter image description here"></a></p>
<p>If you see in the image of my dataframe, I have time points where midnight is a day behind what it should be, which affects my time series graphs.</p>... | <p>Maybe you can do something in this context</p>
<pre><code>df.loc[df['time'] == datetime.time(0, 0), 'date'] += datetime.timedelta(days+1)
</code></pre>
<p>It selects the rows where the time is <code>00:00</code>. Only on that rows, you increase the date-column by one day.</p> | python|datetime|pandas | 0 |
369,183 | 41,576,536 | Normalizing complex values in NumPy / Python | <p>I am currently trying to normalize complex values..
as i don't have a good way of doing this, i decided to divide my dataset into two, consisting of data with only the real part and data only with the imaginary part. </p>
<pre><code>def split_real_img(x):
real_array = x.real
img_array = x.imag
return ... | <p>Basically, two steps would be involved :</p>
<ul>
<li><p>Offset all numbers by the minimum along real and imaginary axes.</p></li>
<li><p>Divide each by the max. magnitude. To get the magnitude of a complex number, simply use <code>np.abs()</code>.</p></li>
</ul>
<p>Thus, the implementation would be -</p>
<pre><c... | python-2.7|numpy|normalization|complex-numbers|activation-function | 1 |
369,184 | 41,469,168 | Understanding how pandas join works | <p>Can somebody please explain this result to me? In particular, I don't know where the <code>NaN</code>s come from in the result. Also, I don't know how the <code>join</code> will decide what row to match with what row in this case.</p>
<pre><code>left_df = pd.DataFrame.from_dict({'unique_l':[0, 1, 2, 3, 4], 'join':[... | <p>The <code>join</code> method makes use of indices. What you want is <code>merge</code>:</p>
<pre><code>In [6]: left_df.merge(right_df, on="join", suffixes=("_l", "_r"))
Out[6]:
join unique_l unique_r
0 a 0 10
1 a 1 10
2 b 2 11
3 b 2 12
4 ... | python|pandas|join|dataframe | 3 |
369,185 | 41,253,326 | Pandas using too much memory with read_sql_table | <p>I am trying to read in a table from my Postgres database into Python. Table has around 8 million rows and 17 columns, and has a size of 622MB in the DB.</p>
<p>I can export the entire table to csv using psql, and then use pd.read_csv() to read it in. It works perfectly fine. Python process only uses around 1GB of m... | <p>You need to set the <code>chunksize</code> argument so that pandas will iterate over smaller chunks of data. See this post: <a href="https://stackoverflow.com/a/31839639/3707607">https://stackoverflow.com/a/31839639/3707607</a></p> | python|postgresql|pandas|sqlalchemy | 4 |
369,186 | 41,314,316 | Tensorflow MNIST: terminate called after throwing an instance of 'std::bad_alloc' | <p>I am trying to implement a Convolutional Neural Network on Tensorflow, using their default MNIST data set.</p>
<pre><code>from __future__ import print_function
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets('MNIST_data', one_hot=True)
def compu... | <p>I think you're running out of memory. It runs okay on my machine (6GB graphics card). Try decreasing the batch size, or using a smaller fully connected layer.</p> | python|tensorflow | 12 |
369,187 | 41,399,714 | Pandas: fillna not working as expected | <p>I have a dataframe with a lot of NAN values:</p>
<p>df = pd.read_csv(filepath)</p>
<p>df looks like:</p>
<pre><code>x001 x002 x003 x004 x005 x006 x007 x008 x009 x010 ... x296 x297 x298 x299 x300 x301 x302 x303 x304 y
0 1540332 NaN NaN NaN 8.0 1 0 1 ... | <p>You don't need a lambda function.</p>
<pre><code>df.fillna(df.mean())
</code></pre> | python|pandas|dataframe | 1 |
369,188 | 41,670,471 | Python - data displaying incorrectly (Matplotlib) | <p>Im a newbie to python, i have a question. I am loading data from a CSV file, removing duplications, saving the removed duplications csv file, then loading the correct CSV files and generating the graph. My issue is however, the graphs are not being displyed correctly, as in the totals are wrong. I know the program i... | <p>Solution was to add 'del writer'after each Create database of duplicates</p> | python|numpy|matplotlib | -1 |
369,189 | 41,483,772 | Using queues in TensorFlow to load images and labels from text file | <p>I am trying to run a very simple neural network in TensorFlow which will learn to classify images. So far it is extremely simple, because I am still learning the framework.</p>
<p>So far I am struggling to load the data - my data is in TXT file. Every line contains ID of the photo and a binary number which is used ... | <p>It might be caused by <code>num_epochs=1</code> here <code>tf.train.slice_input_producer([filenames, labels], num_epochs=1, shuffle=True)</code>. You can check api of <code>slice_input_producer</code>, where it explains: num_epochs: An integer (optional). If specified, slice_input_producer produces each slice num_ep... | python|python-3.x|queue|tensorflow|neural-network | 2 |
369,190 | 41,580,776 | Create new columns for a dataframe by parsing column values and populate new columns with values from another column python | <p>I need to add new columns to a dataframe based on lists within a certain column. The new columns need to be a set derived from all the lists in the column. </p>
<p>I then have another column with lists corresponding to the first but the data is slightly different. I need these values to populate the new columns if ... | <p>It seems that you have multiple values in each individual cell (from your previous and current questions). It would be far far easier to tidy up your data first and then continue with your analysis. Try to put each value in each column in its own cell.</p>
<pre><code>df1 = pd.concat([df[col].str.split('|', expand=T... | python|performance|pandas | 2 |
369,191 | 41,269,239 | Group by with a pandas dataframe using different aggregation for different columns | <p>I have a pandas dataframe <code>df</code> with columns <code>[a, b, c, d, e, f]</code>. I want to perform a group by on <code>df</code>. I can best describe what it's supposed to do in SQL:</p>
<pre><code>SELECT a, b, min(c), min(d), max(e), sum(f)
FROM df
GROUP BY a, b
</code></pre>
<p>How do I do this group by... | <p>use <code>agg</code></p>
<pre><code>df = pd.DataFrame(
dict(
a=list('aaaabbbb'),
b=list('ccddccdd'),
c=np.arange(8),
d=np.arange(8),
e=np.arange(8),
f=np.arange(8),
)
)
funcs = dict(c='min', d='min', e='max', f='sum')
df.groupby(['a', 'b']).agg(funcs).reset_i... | sql|python-2.7|pandas | 1 |
369,192 | 41,474,136 | Disable SSE4.1 when compiling TensorFlow | <p>I followed the instruction on TF's website and install the TensorFlow from the source code. I did not change any configurations, all are the default values.</p>
<p>When I run my program (which works fine when using the pre-complied TensorFlow 0.12 wheel), it gives me the following error</p>
<p><code>
F tensorflow/... | <p><a href="https://github.com/tensorflow/tensorflow/blob/c4b09b5df79625a70853fd66b5caa7dd92fb4d1f/tensorflow/tensorflow.bzl#L130" rel="noreferrer">This line</a> in <code>tensorflow/tensorflow.bzl</code> is responsible for enabling SSE 4.1 instructions in all x86 builds. If you delete that line, the resulting build sho... | tensorflow | 5 |
369,193 | 41,651,350 | Pandas read_html results in TypeError | <p>I'm using bs4 to parse a html page and extract a table, sample table given below and I'm trying to load it into pandas but when i call <code>pddataframe = pd.read_html(LOTable,skiprows=2, flavor=['bs4'])</code> I get the error listed below but I can print the tables prettified by bs4</p>
<p>Any suggestions how I ca... | <p>Thanks for the pointers from all the suggested answers and comments, my rookie mistake was I had the table in a variable after extracting it using bs4.
I was running <code>pd.read_html(LOTable,skiprows=2, flavor='bs4')</code> when I needed to run <code>pd.read_html(LOTable.prettify(),skiprows=2, flavor='bs4')</code>... | python|pandas | 8 |
369,194 | 41,573,232 | Pandas equivalent to SQL window functions | <p>Is there an idiomatic equivalent to SQL's window functions in Pandas? For example, what's the most compact way to write the equivalent of this in Pandas?:</p>
<pre><code>SELECT state_name,
state_population,
SUM(state_population)
OVER() AS national_population
FROM population
ORDER BY state... | <p>For the first SQL:</p>
<pre><code>SELECT state_name,
state_population,
SUM(state_population)
OVER() AS national_population
FROM population
ORDER BY state_name
</code></pre>
<p>Pandas:</p>
<pre><code>df.assign(national_population=df.state_population.sum()).sort_values('state_name')
</co... | python|sql|pandas|window-functions | 22 |
369,195 | 41,627,892 | Pandas - Adding dataframe with same name using to_hdf doubled file size | <p>I am newbie in Pandas module. I created dataframe and save it with name <code>"dirtree"</code> using <code>to_hdf</code>:</p>
<pre><code>df.to_hdf("d:/datatree full.h5", "dirtree")
</code></pre>
<p>I repeated actions above. After that, when I check file size, it is doubled. I guess my second dataframe was appended... | <p>I could reproduce this issue in the following way:</p>
<p>Original sample DF:</p>
<pre><code>In [147]: df
Out[147]:
a b c
0 0.163757 -1.727003 0.641793
1 1.084989 -0.958833 0.552059
2 -0.419273 -1.037440 0.544212
3 -0.197904 -1.106120 -1.117606
4 0.891187 1.094537 100.00... | python-3.x|pandas|dataframe|hdf5 | 3 |
369,196 | 41,353,451 | What are all my variables duplicated in Tensorboard? | <p>I'm new to Tensorflow and am running a basic CNN. As a way of visualising the training process, I build a summary with loss and accuracy in order to view later in Tensorboard like this:</p>
<pre><code>tf.summary.scalar("loss", cost)
tf.summary.scalar("accuracy", accuracy)
</code></pre>
<p>I initialise the summarie... | <p>I found the culprit and thought I'd post it here for future reference.</p>
<p>It turns out the I needed to call <code>tf.reset_default_graph()</code> before each run.</p> | python|tensorflow|tensorboard | 3 |
369,197 | 41,612,539 | python: Improving the way I am reading a large (5GB) txt file | <p>I am actually using <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html" rel="nofollow noreferrer"><code>pandas.read_csv</code></a> to read a large (5GB, ~97million rows X 7 columns) txt file with python (a point cloud).</p>
<p>My need is to read the first three columns (which repres... | <p>Since I don't have a 5GB file ready for testing I can only guess that these two issues slow you down:</p>
<ol>
<li>reading the file line by line (and converting each line to a dataframe)</li>
<li>complicated logic including <code>locals()</code> and element access for each line</li>
</ol>
<p>To address these point... | python|pandas|numpy|io|large-files | 2 |
369,198 | 41,238,053 | Issue calling a function | <p>I have a dataframe called <code>ro</code> which has all claims for automotive parts, What I want now is to create a function called <code>part_dataframe</code> where I can subset the original <code>ro</code>into a new dataframe with only a particular part, let say compressor with the subset name as <code>comp_claims... | <pre><code>ro = pd.DataFrame(
{'Part No.': np.arange(10)}
)
def part_dataframe(first_frame, type_number, number):
return first_frame.loc[first_frame[type_number] == number]
subset = part_dataframe(ro, 'Part No.', 3)
subset
</code></pre>
<p><a href="https://i.stack.imgur.com/1hFXr.png" rel="nofollow noreferre... | python|function|pandas|dataframe | 2 |
369,199 | 41,483,095 | parsing CSV in pandas | <p><a href="https://i.stack.imgur.com/tT3VJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tT3VJ.png" alt="This is a fragment of the df when visualized"></a></p>
<p>I want to calculate the average number of successful Rattatas catches hourly for this whole dataset. I am looking for an efficient way... | <p>You don't need any loops. Try this. I think logic is rather clear.</p>
<pre><code>import pandas as pd
#read csv
df = pd.read_csv('pkmn.csv', header=0)
#we need apply some transformations to extract date from timestamp
df['time'] = df['time'].apply(lambda x : pd.to_datetime(str(x)))
df['date'] = df['time'].dt.date... | python|csv|pandas|dataframe | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.