Hot answers tagged

3

To select the most different rows, you would need to define first what you consider different. For ages and scores, subtracting values would work, for example: Row1 Age is 38 Score is 0.2 Row2 Age is 87 Score is 1.0 Difference by numeric feature: Age Diff is 49 Score Diff is 0.8 Those values could be normalized or weighted to account for different ...


2

Try this: jupyter nbconvert --to pdf --TemplateExporter.exclude_input=True my_notebook.ipynb This also works for html output. You will find the documentation for this and other options here: https://nbconvert.readthedocs.io/en/latest/config_options.html?highlight=TemplateExporter.exclude FYI, for complex notebooks, this may generate errors depending on your ...


2

The most basic method that springs to mind is split of a test set: Take the data where you have recorded all variables which you might need to extrapolate in another set, and split of a percentage of that and "mask" or hide the variable you wish to interpolate in this split (maybe using the data from the other part of the split if you're using some ...


2

Well assuming df is your Pandas dataframe you could sort it by Artist and then do something like this: df = df.drop_duplicates(subset='Artist', keep='first')


2

Welcome to the community! There are more intuitive ways to do this like calculating pair-wise distances from vectors in the space but this is not scalable properly. The second point is that even if you want to go this way, it is better to put them in a weighted graph through e.g. Networkx library and then find longest path between two nodes or detecting ...


2

Use pandas.DataFrame.reindex() df = pd.concat((df1, df2), axis=1) #reorder columns column_names=["A","C","B","D"] df = df.reindex(columns=column_names)


1

To build your data use sth like: import copy, json def make_objects(ref_obj, df): objects = [] for i in range(len(df[df.columns[0]].values)): cobj = copy.deepcopy(ref_obj) cobj['data_sample'] = {} for col in df: cobj['data_sample'][col] = int(df[col].values[i]) objects.append(cobj) return objects df = pd....


1

Here is a quick solution that does not do it in-place but takes up extra space: def transform_series(x, chunk_size): df = pd.DataFrame() for i in range(chunk_size): df[f'column_{i+1}'] = x[i::chunk_size].reset_index(drop=True) return df input_series = pd.Series([10,11,12,13,14,15]) transformed_df = transform_series(input_series, ...


1

The error is caused by passing a numpy array into a function that expects an integer value. read_csv() will read a file, and create a numpy array from the data inside. You can slice off the column of the numpy array that you want to use, convert it to a list and then pass this one by one into classes[] # this should work, but change the value of 12 to the ...


1

df.loc['Total'] = pd.Series([df['Commission'].sum(),df['Profit'].sum(),df['Net profit'].sum()], index = ['Commission','Profit','Net profit'])


1

TypeError: unhashable type: 'list'. You will get this error when you are trying to put list as key in dictionary or set because list is unhashable object. Example you trying to input code such as dict1 ={ 1:'one', [2]:'two'} print(dict1) O/p: TypeError Traceback (most recent call last) in ----> 1 dict1 ={ 1:'one', [2]:'two'} 2 print(dict1) TypeError: ...


1

I agree to opinions said before. Just as alternative, if you see that customer behavior is too different if it is a guest or not, depending also on model you use, probably it would make sense to use two different models. For example, if you know will use LogisticRegression and not regular customers behavior is distributed in bigger range, then probably you ...


1

Welcome to Data Science at StackExchange, One way to accomplish this is to use the stratify option in train_test_split, since you are already using that function (this will also work for ensuring your labels are equally distributed, very useful in modelling an unbalanced dataset): Train,Test = train_test_split(df, test_size=0.50, stratify=df['B']) In my ...


1

So, your question is to instantiate a new data frame df2 from another data frame df1, by simply selecting rows. You can do this by indexing. What is great by pandas DataFrames is that you can index a DataFrame using a list of indices. df2 = df1.iloc[[list of indices],:]


1

EDIT: Thanks for you clarifying the question. So now the problem is checking the counts of ids in two data frames are the same. Here is how you could go about it: d1 = pd.DataFrame(df1[~df1['A'].isnull()].groupby("id").size()) d2 = pd.DataFrame(d[~d['A'].isnull()].groupby("id").size()) d = pd.merge(d1,d2,on="id") ids_ = d[d[&...


1

To Tokenise, clean up symbols (i.e. Normalise), etc. just use one of the widely used NLP libraries, they should be able to do most of the work for you. Examples include: NTLK Spacy SparkNLP .. and many more. Perhaps look up some articles comparing their strengths and weaknesses on Google to decide what's best with your project. As for the detecting English ...


Only top voted, non community-wiki answers of a minimum length are eligible