I have a DataFrame with multiple columns: Now I want to break column C(whose each entry is separated by n) into multiple column like this: I tried few techniques but can’t make it. I tried to use df.apply but not able to fix NA columns. Is there a way to cleanly achieve this? Thanks. Answer A solution u…
Tag: pandas
Create new dataframe from an existing dataframe
I have a pandas dataframe with say 6 columns. 3 of the columns are of length 5. Two of the columns are of length 2 and the last column is of length 8. The columns are randomly positioned in the dataframe. I would like to create 3 new dataframes. The first dataframe should only contain all the columns whose le…
Pandas Assign Same Value to All Unique Values in Column
H, I have a dataset with two columns, one of them is target. If I group all the unique values in target, I get an array of 826 elements. My problem is when trying to assign some values based on this uniqueness. I have a second array, called array with contains a total of 826 values (of string type) to
Questions about In-place memory operations in pandas (1/2)
I was explaining[1] in-place operations vs out-of-place operations to a new user of Pandas. This resulted in us discussing passing objects by reference of by value. Naturally, I wanted to show pandas.DataFrame.values as I thought it shared the memory location of the underlying data of the DataFrame. However, …
Build a dask dataframe from a list of dask delayed objects
I have a list of dask delayed objects Portfolio_perfs: Each delayed object is a numpy array of length 2 I want to build the following dataframe without using dask.compute: How can I build this dask dataframe without going through dask.compute? Thank you Answer Since each delayed object is a numpy array, you a…
LSTM neural network test to predict SPY prices giving me this error after training
Error is as follows: My Code is as follows: Not sure what’s going on…. Answer Just check you train dataset, there is no Open column there, so dataset_train[‘Open’] fails: Output: Maybe you want to use dataset_train[‘Value’] instead
Combine all column elements except two particular columns
I want to combine the elements in all columns except two columns, ‘SourceFile’ and ‘Label’. I tried the above code. Which resulted in value error. There is so many columns. So I can’t use Answer col != [‘SourceFile’,’Label’] is syntactically wrong and it g…
Creating a list merging the elements of a previous list and the values of a specific column of a data frame
I want to create a new list merging the elements of a previous list plus the values of a specific column of one data frame. See the example below. The list I already have: The column: The desired output: Answer IIUC, just loop over them:
Counting unique mentions in Pandas dataframe column while grouped by multiple other columns
For a school project I am attempting to determine the number of mentions specific words have in Reddit titles and comments. More specifically, stock ticker mentions. Currently the dataframe looks like this (where type could be a string of either title or comment): Where the mentions column contains a set of t…
Pandas create column of dictionaries based on condition from another column
Let’s say if I have a Pandas df called df_1 like this: id date_created rank_1 rank_2 rank_3 rank_dict 2223 3/3/21 3:26 www.google.com www.yahoo.com www.ford.com {www.google.com:3, www.yahoo.com:2, www.ford.com:1} 1112 2/25/21 1:35 www.autoblog.com www.motor1.com www.webull.com {www.autoblog.com:3, www.m…