Skip to content

Tag: pandas

Dropping Multiple Columns from a dataframe

I know how to drop columns from a data frame using Python. But for my problem the data set is vast, the columns I want to drop are grouped together or are basically singularly spread out across the column heading axis. Is there a shorter way to slice or drop all the columns with fewer lines of code rather tha…

pandas concat generates nan values

I am curious why a simple concatenation of two dataframes in pandas: of the same shape and both without NaN values can result in a lot of NaN values if joined. How can I fix this problem and prevent NaN values being introduced? Trying to reproduce it like failed e.g. worked just fine as no NaN values were int…

quickest way to swap index with values

consider the pd.Series s What is the quickest way to swap index and values and get the following Answer One posible solution is swap keys and values by: Another the fastest: Timings: If length of Series is 1M: