Skip to content
Advertisement

Tag: pandas

Trying to ignore Nan in csv file throws a typeerror

I’m loading a local csv file that contains data. I’m trying to find the smallest float in a row thats mixed of NaN and numbers. I have tried using the numpy function called np.nanmin, but it throws: Any suggestions to why nanmin might not work? A link to the entire csv file: http://www.sharecsv.com/s/5aea6381d1debf75723a45aacd40abf8/database.csv Here is a sample of my coun_weight:

applymap() does not work on Pandas MultiIndex Slice

I have an hierarchical dataset: I want to apply a function to all values under the columns A. I can set the value to something: Easy enough. Now, instead of assigning a value, if I want to apply a mapping to this MultiIndex slice, it does not work. For example, let me apply a simple formatting statement: This step works

pandas DataFrame style, highlight nan’s

Say with this DataFrame How can I check which element is nan inside df.applymap? (ie, not using df.isnull) The problem comes from where I want to use the pandas html styling. We have the built-in nan highlighting but it changes the background colour, instead I want “nan” to be displayed in red. So I need to do it myself with

Use .corr to get the correlation between two columns

I have the following pandas dataframe Top15: I create a column that estimates the number of citable documents per person: I want to know the correlation between the number of citable documents per capita and the energy supply per capita. So I use the .corr() method (Pearson’s correlation): I want to return a single number, but the result is: Answer

replace part of the string in pandas data frame

I have pandas data frame in which I need to replace one part of the vale with another value for Example. I have out of which I’d like to replace ony the HF – part thus the result would be I have tried pd.replace() but it doesnt work as I need only one part of the string replaced, rather than

pandas convert columns to percentages of the totals

I have a dataframe with 4 columns an ID and three categories that results fell into I would like to convert it to percentages ie: this seems like it should be within pandas capabilities but I just can’t figure it out. Thanks in advance! Answer You can do this using basic pandas operators .div and .sum, using the axis argument

Advertisement