New answers tagged

0

If you want to add the data from df1 to df2 you can use pandas.merge. Given that you want to keep all records from df2 and only add data from df1 for the identifiers in df2 you can use the following syntax: import pandas as pd pd.merge(df2, df1, how="left", on="id_column")


1

The reason the other bars are missing is because of your method of summing the values and the missing values in your dataset. The way you are adding the values together means that if even one value is missing (NA) the total for that column will be missing as well, and as a result, will not be in your final plot. It is better to use pandas built-in methods (...


1

First answers is close, the only thing you need to do is merge both data frames using two fields. You do not need both data frames to have the same length at all Try: pd.merge(df1, df2, on = ["number","trans"], how = "left")


1

Simplest approach First a very fast and perhaps practical approach: just remove them with replacing them! From your bar chart, it seems you have a lot of transactions - several hundred thousand. Removing a few hundred (I can't even see a bar for the > $600 transactions) and not replacing them wouldn't mean the remaining data is unusable. Replacing those ...


0

You can use any of these below for replacing the outliers Quantile-based Flooring and Capping In this technique, we will do the flooring (e.g., the 10th percentile) for the lower values and capping (e.g., the 90th percentile) for the higher values. The lines of code below print the 10th and 90th percentiles of the variable 'amount', respectively. These ...


2

You have a combination of two problems in your data: imbalance missing values In your experiments there's a confusion about what the true distribution of the data is (or should be): either the "real data" is 97% no, or the "real data" is after removing missing values in which case it's almost balanced. It's very important to decide this ...


1

I'm going to just answer about the difference between the two functions qcut and cut because it's a very important difference: the first qcut is indeed about quantiles, which means that it's about dividing the data into bins, each containing an equal number of points. For instance if you use deciles it means that there is the same number of people in the ...


0

Here is one approach... import pandas as pd df = pd.DataFrame({'first': ['bar', 'bar', 'baz', 'baz', 'foo', 'foo', 'qux', 'qux'], 'second': ['one', 'two', 'one', 'two', 'one', 'two', 'one', 'two'], 'value': [0.361041, 0.476720, 0.565781, 0.848519, 0.405524, 0.882497, 0.488229, 0.303862]}) df = df.set_index(['first', '...


0

How do you get to the second picture from that code? I wil give you rough set of steps to follow along with the main function names. you can search through the pandas documentation for more details. initialise some empty lists: ticker_names=[] dataframes=[] Loop over the files and read them using df = pd.read_csv(file_name) Take just the Close column of ...


2

It depends on what problems you are afraid of: regarding "technical" issues, it should be ok having NaNs in your dataframe and, afterwards, applying the pd.isna(column_name) per attribute to get a boolean mask to find those unknown values per column, more info here in case your problem is not knowing the actual values, one option is imputation, ...


0

In this case concat is what you want You can read the data into a dataframe using normal pd.read_csv df1 = pd.read_csv('one.csv') df2 = pd.read_csv('two.csv') Then apply pd.concat with axis=0 and ignore_index=True. By passing axis=0 here you are stacking the df's on top of each other. The columns that do not match will result in a NaN. You can do a fillna(-...


0

It is really hard to figure out the logic behind what you are doing, it look odd But assuming you are trying to apply a preprocessing step to a data frame I would go as follows: from sklearn.compose import make_column_transformer from sklearn.preprocessing import OrdinalEncoder ordinal_features=['LotShape','ExterQual','ExterCond','BsmtQual','BsmtCond', '...


0

In the documentation categories parameter is explained as: categories[i] holds the categories expected in the ith column. The passed categories should not mix strings and numeric values, and should be sorted in case of numeric values. You can pass a two dimensional array to the categories parameter in which each element of the array is an another array holds ...


1

If you want to apply the result of fit_transform, you must assign to your columns. columns = ['S_LENGTH', 'S_WIDTH', 'P_LENGTH', 'P_WIDTH'] min_max = preprocessing.MinMaxScaler() df[columns] = min_max.fit_transform(df[columns]) df.head() Output ID S_LENGTH S_WIDTH P_LENGTH P_WIDTH SPECIES 0 1 0.0 0.0 1.0 0.0 VIRGINICA 1 ...


0

You can use df.select_dtypes(exclude='object') to exclude categorical columns. Also while importing dataset, set the index_col='ID' to use ID as index instead of column.


0

This solution works well but I don't know why above don't work! Imputer = SimpleImputer(missing_values=np.nan, strategy='most_frequent') for i in range(2): for j in range(1,4): ls = np.array(df.Age[((df.Sex==i) & (df.Pclass==j))]).reshape(-1,1) df.Age[((df.Sex==i) & (df.Pclass==j))] = Imputer.fit_transform(ls)[:,0] df.Age.isnull()....


1

You are using the right method but in a wrong way :) nan_to_num is a method of numpy module, not numpy.ndarray. So instead of calling nan_to_num on you data, call it on numpy module giving your data as a paramter: import numpy as np data = np.array([1,2,3,np.nan,np.nan,5]) data_without_nan = np.nan_to_num(data) prints: array([1., 2., 3., 0., 0., 5.]) In ...


0

@user575406's solution is also fine and acceptable but in case the OP would still like to express the Distributed Lag Regression Model as a formula, then here are two ways to do it - In Method 1, I'm simply expressing the lagged variable using a pandas transformation function and in Method 2, I'm invoking a custom python function to achieve the same thing. ...


1

This information is in the documentation of Seaborn. They show a bootstrap confidence interval, computed by resampling units (rows in the 2d array input form). By default, in seaborn version 0.8.1 it uses 95% of confidence interval, which is equivalent to a standard error. This value is a parameter that can be changed.


2

I think the main problem is how you are using BERT, as you are processing your text sentence by sentence. Instead, you should be feeding the input to the model in mini-batches: Neural networks for NLP are meant to receive not only one sentence at a time, but multiple sentences. The sentences are stacked together in a single tensor of integer numbers (token ...


3

There are several things that could make your code faster: Stop using Pandas. Pandas is not designed for large-scale, fast text processing. It would be better to switch to something like Apache Arrow which is designed for efficient analytic operations on modern hardware. Refactor code to avoid casting into memory-inefficient data types. progress_notes['...


Top 50 recent answers are included