Category "pandas"

Pandas: how to get index value of non-unique index

I have a data frame with a date time index where index values are non unique (see last two index values). I would like to get the next valid index value given a

index of non "NaN" values in Pandas

From Pandas data frame, how to get index of non "NaN" values? My data frame is A b c 0 1 q1 1 1 2 NaN 3 2 3 q2 3 3 4 q1

Insert a row to pandas dataframe

I have a dataframe: s1 = pd.Series([5, 6, 7]) s2 = pd.Series([7, 8, 9]) df = pd.DataFrame([list(s1), list(s2)], columns = ["A", "B", "C"]) A B C 0 5

python: how to melt dataframe retaining specific order / custom sorting

I have a dataframe df Cat B_1 A_2 C_3 A 1 2 3 B 4 5 6 C 7 8 9 which I want to convert into a dataframe so that the rows in column

How to add custom annotations to a stacked bar

I am trying to annotate a stacked histogram in Seaborn with the hue for each segment in the histogram for readability reasons. I've attached sample data below a

Can't convert column with pandas.to_numeric

I have a column of data, here is a snip of it: a = data["hs_directory"]["lat"][:5] 0 40.67029890700047 1 40.8276026690005 2 40.842414068000494 3

kronecker product pandas dataframes

I have two dataframes A B 0 1 2 1 1 2 2 1 2 and C D 0 1 4 1 2 5 2 3 6 I need the mean of the cross products (AC, AD, BC, BD).

Convert string to_datetime with wrong place day and month

I have a dataset like this df = pd.DataFrame({'time': ('08.02.2020', '21.02.2020', '2020.05.04')}) df I do pd.to_datetime(df['time']) 0 2020-08-02 1 2020-0

Python Pandas Dataframe Datetime Range

Here is my code block: import pandas as pd import datetime as dt first_day = dt.date(todays_year, todays_month, 1) print(first_day) >2021-02-01 print(type(

Is there a way to show the probability within hue category in Seaborn histogram

For example, I have a dataframe: data = {'1': [1, 1, 2,2,2,2,2, 3,2.5,2.5,1.5,2,2.5,2, 2, 3,1.5,2], '2': [1,1,1,1,1,1,1,1,1,1,1,1,1,1,0, 0,0,0], }

Can't manipulate dataframe in pandas

Don't understand why I can't do even the most simple data manipulation with this data i've scraped. I've tried all sorts of methjods to manipulate the data but

Adding a fixed value to a DF

I have generated a DF from the below code: url='https://www.rootsandrain.com/event4493/2017-aug-26-uci-world-cup-dh-7-val-di-sole/results/' response = requests.

convert column to table header in pandas dataframe

I have this dataframe: identifier_1 measure Value identifier_2 abc height 12 oii abc weig

How could I detect subtypes in pandas object columns?

I have the next DataFrame: df = pd.DataFrame({'a': [100, 3,4], 'b': [20.1, 2.3,45.3], 'c': [datetime.time(23,52), 30,1.00]}) and I would like to detect subty

How can I plot separate Pandas DataFrames as subplots?

I have a few Pandas DataFrames sharing the same value scale, but having different columns and indices. When invoking df.plot(), I get separate plot images. what

Pandas Melt several groups of columns into multiple target columns by name

I would like to melt several groups of columns of a dataframe into multiple target columns. Similar to questions Python Pandas Melt Groups of Initial Columns In

'bz2 is module not available' when installing Pandas with pip in python virtual environment

I am going through this post Numpy, Scipy, and Pandas - Oh My!, installing some python packages, but got stuck at the line for installing Pandas: pip install -

Simultaneously melt multiple columns in Python Pandas

wondering if pd.melt supports melting multiple columns. I have the below examples trying to have the value_vars as list of lists but i am getting an error: Val

How to flatten multilevel/nested JSON?

I am trying to convert JSON to CSV file, that I can use for further analysis. Issue with my structure is that I have quite some nested dict/lists when I convert

Single column to multiple columns with columns as heading and fill with binary values

Given column in the csv file labels ['N'] ['C'] ['D'] ['A'] ['D','C'] ['H'] ['D','G'] ['M'] ['O'] I want the labels a