New answers tagged

0

My guess would be that in the following piece of code: for i,j in enumerate(indices): temp = [round(distances[i][0],2), clean_org_names.values[j][0][0],unique_org[i]] matches.append(temp) The variable (array element): distances[i][0] contains the top element match for the $i^{th}$ line. Replace the second array index so it becomes: distances[i][1] ...


0

Aha! For some reason, when I named a variable that pointed to a value in a dataframe, and then tried to use the variable to put it back into the table replacing other cells, it changed the dtype. That's why I was getting NaNs. I just had to convert it to a usable type using tolist. As for the nearest-value identification, this seems to have worked: Pfinal =...


1

Use pickle package, it's meant to export and/or load python objects. You can find information of how is done in this topic of stack overflow: https://stackoverflow.com/questions/4529815/saving-an-object-data-persistence


0

df_2['bigram_scored'] = df_2['bigram_finder'].apply(lambda x: x.score_ngrams(bigram_measures.raw_freq))


0

The next snippet of code should be useful dt.groupby(['level1', 'level2']).agg({'level3':'sum'}).sort_values(by = ['level3'], ascending = False) where dt is your original dataframe and level3 is your numerical column which you would like to sort and considering that you're suming the value of level3 grouping by level1 and level2.


4

Searching the source code of Sklearn for SimpleImputer (with strategy= "most_frequent"), the most frequent value is calculated within a loop in python, therefore that is the part of code that is so slow. In the source code of SimpleImputer there is also the comment that explains why they do not use the scipy.stats.mstats.mode, which is mush faster: scipy....


0

If the created_at column is of the datetime type, you can use the .dt method to only get the date as follows: df["date_column"] = df["created_at"].dt.date This will return the following column: date_column 2018-10-08 2018-09-26 2018-08-07 2018-10-04 2019-02-06 2019-02-10 2019-03-07 2018-09-13 2018-03-23


0

This snippet will return integer value of total number of columns with missing value: (df.isnull().sum() > 0).astype(np.int64).sum()


1

#Taking care of missing data from sklearn.impute import SimpleImputer imputer=SimpleImputer(missing_values=np.nan,strategy='mean') imputer=imputer.fit(X[:,1:3]) X[:,1:3]=imputer.transform(X[:,1:3]) Result array([['France', 44.0, 72000.0], ['Spain', 27.0, 48000.0], ['Germany', 30.0, 54000.0], ['Spain', 38.0, 61000.0], ['Germany'...


1

I'm assuming the displayed time series shows number of jobs submitted per 15 minute interval. Categorical features Divide the time series per category. If the jobs can be divided into type1, type2, type3 then make a time series for each type and predict each series individually. So type1-time series has number of type1-jobs per 15 minute interval. ...


1

You sure can. One solution off the bat is to extend your estimator that takes object type variables. So what does that mean. Library that you said are all estimators in the sklearn form fit, predict methodology. So all you have to do is something as follows: > class modifiedTraf(oldTraf): > def __init__(self): > super(...


0

Replace the missing value with empty string and add these columns up Classes.fillna(value='').sum(axis=1)


0

Sorry, that's not the issue, avg_Nox is only a label, that does not change the name of column. If I add a simple agg function instead of the lambda function the code runs fine. For example: bh_df.groupby('CAT.MEDV').agg( avg_Nox=('NOX', 'mean'), min_Nox=('NOX', min)) works fine.


3

Because there is no more column "NOX" you changed it in the previous mean aggregation. Try "avg_Nox" or whatever column name you get after applying your first aggregation function bh_df.groupby('CAT.MEDV').agg( avg_Nox=('NOX', 'mean'))


1

Not sure what you mean by "unique", I guess if there're n critics, m items, what you need is a dataframe with shape n*m rows and 3 columns, right? If so, try the demo: #1. the original dataframe df = pd.DataFrame([['a',1,5],['b',2,3],['b',3,2],['c',8,1],['a',1,5]],columns=['critic','item','rating']) #2. create the first two columns(critic, item) by their ...


Top 50 recent answers are included