Skip to content
Advertisement

Tag: dataframe

convert list of strings to panda dataframe with types

I have a list of a list of numbers where two rows are strings, e.g. A = [[1,’5.4′,’2′],[2,’6′,’3′]] How do I convert this to a pandas dataframe, such that the 1st and 3nd columns are integers and the 2nd column is a float by pd.DataFrame(A,dtype=float) it converts all to floats. Answer Here is a possible solution: If you don’t want

how to apply a class function to replace NaN for mean within a subset of pandas df columns?

The class is composed of a set of attributes and functions including: Attributes: df : a pandas dataframe. numerical_feature_names: df columns with a numeric value. label_column_names: df string columns to be grouped. Functions: mean(nums): takes a list of numbers as input and returns the mean fill_na(df, numerical_feature_names, label_columns): takes class attributes as inputs and returns a transformed df. And here’s

Excel column manipulation

I am trying to find cell named North and take everything below it I know that we can easily locate this using loc and iloc, but in my case it may vary every time my app opens new excel file. I tried using str.contains Answer Try with iloc and idxmax:

Matplot lib generates Date in X-axis from Jan 1970

I have date index available in the following format: But the following code generates wrong graph: Answer Your dataframe index is likely in the wrong format: str. You can check this with df.info(), if you have something like: If that’s the case, you need to convert index type from str to datetime with: Code example: Without to_datetime conversion: With to_datetime

Advertisement