I have come across an issue with the np.select section of my code and have reproduced a minimal-reproducible-example to seek some advice as to why ValueError: -1 is not in range is being returned rather than nan Using df[‘number’][3] when number = 1 I would expect to return nan since the value loc…
Tag: pandas
How to convert multiple pandas columns from string boolean to boolean?
I have this dataframe I want to convert the string booleans to booleans. I have tried and but neither of these worked. Is it possible to do convert the type of multiple columns in a single line or do I have to convert the relevant columns one at a time? Answer You can use the dictionary version of replace.
Problems with Multiindex from pd.Crosstab when appending non present row data
Morning All, Happy Friday. I have some excel output which shows Client, their Sector and the counts of their Result via a crosstab command. This works well: The excel extract meets the requirements. An additional request has come in to add all other possible clients which are not present in the current months…
Python- compress lower end of y-axis in contourf plot
The issue I have a contourf plot I made with a pandas dataframe that plots some 2-dimensional value with time on the x-axis and vertical pressure level on the y-axis. The field, time, and pressure data I’m pulling is all from a netCDF file. I can plot it fine, but I’d like to scale the y-axis to b…
Python Pandas Filter but results are inversed
Hi I’ve built a filter where I expect the results to only show ‘New’. However the result shows everything but new? Thoughts? TIA Neil Answer The ~ negates/inverts the filter. Just use .loc[filt] instead of .loc[~filt] to get the un-negated result.
TypeError: can’t convert type ‘NoneType’ to numerator/denominator
Here I try to calculate mean value based on the data in two list of dicts. Although I used same code before, I keep getting error. Is there any solution? Too see csv files: https://repl.it/@rmakakgn/SVE2 Answer .get method of dict return None if given key does not exist and statistics.mean fail due to that, c…
Divide dataframe column by a specific cell
I want to divide a dataframe column by a specific cell in the same dataframe. I have a dataframe like this: I want to compute the score_ratio by dividing the score by the ‘baseline’ score of that date. The score_ratio for (date, type) = (20201101, experiment1) should be obtained by dividing its sc…
Most efficient way to combine large Pandas DataFrames based on multiple column values
I am processing information in several Pandas DataFrames with 10,000+ rows. I have… df1, student information df2, student responses I want… a DataFrame with columns for the class number, student ID, and unique assignment titles. The assignment columns should contain the students’ highest sco…
How to make a sum in NetCDF4 by xarray
I would like to make a monthly sums of my NetCDF4 file from daily values for precipitation. However, I am quite not sure what I am doing wrong. It seems that something has changed from the code in this post: Sum a daily time series into a monthly time series with a NaN value threshold I didn’t find anyt…
I cant find why `.read_csv` cannot make a dataframe for `.shape` to recognize
Following a machine learning guide here: https://www.pluralsight.com/guides/scikit-machine-learning/ Running Python 3.8, might have a hunch that I need to run it in IPython but I think that opens up a new can of worms. Also have all imported these libraries installed. I left %matplotlib inline as a comment be…