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.co…
Tag: pandas
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…
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…
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 ret…
Python/Pandas: If Column has multiple values, convert to single row with multiples values in list
In my DataFrame, I have many instances of same AutoNumber having different KeyValue_String. I would like to convert these instances to a single row where the KeyValue_String is a list comprised of the multiple unique values. The desired output would look like this, except I want to keep all of the other colum…
How to save a new sheet in an existing excel file, using Pandas?
I want to use excel files to store data elaborated with python. My problem is that I can’t add sheets to an existing excel file. Here I suggest a sample code to work with in order to reach this issue This code saves two DataFrames to two sheets, named “x1” and “x2” respectively. …
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
Inconsistency when setting figure size using pandas plot method
I’m trying to use the convenience of the plot method of a pandas dataframe while adjusting the size of the figure produced. (I’m saving the figures to file as well as displaying them inline in a Jupyter notebook). I found the method below successful most of the time, except when I plot two lines o…
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, …
How to import all fields from xls as strings into a Pandas dataframe?
I am trying to import a file from xlsx into a Python Pandas dataframe. I would like to prevent fields/columns being interpreted as integers and thus losing leading zeros or other desired heterogenous formatting. So for an Excel sheet with 100 columns, I would do the following using a dict comprehension with r…