What do you want to save?
Add Code snippet
New code examples
-
Python 2021-10-22 06:46:08
pandas - unlist values and put in a row
# Version for one list column to put in signle row lst_col = 'my_list_var' r = pd.DataFrame({ col:np.repeat(df[col].values, df[lst_col].str.len()) for col in df.columns.drop(lst_col)} ).assign(**{lst_col:np.concatenate(df[lst_col].values)... Add solution -
Python 2021-10-20 01:46:11
get columns containing string
import pandas as pd data = {'spike-2': [1,2,3], 'hey spke': [4,5,6], 'spiked-in': [7,8,9], 'no': [10,11,12]} df = pd.DataFrame(data) spike_cols = [col for col in df.columns if 'spike' in col] print(list(df.columns)) print(spike_cols) Add solution -
Python 2021-10-14 21:55:06
split coumn of df into multiple dynamic columns
d = [pd.DataFrame(df[col].tolist()).add_prefix(col) for col in df.columns] df = pd.concat(d, axis=1) id0 id1 id2 value0 value1 value2 0 10 10 NaN apple orange None 1 15 67 NaN banana orange None 2 12 34 45.0 apple ... Add solution -
Python 2021-10-04 18:21:02
python - find specific name in a df
import pandas as pd data = {'spike-2': [1,2,3], 'hey spke': [4,5,6], 'spiked-in': [7,8,9], 'no': [10,11,12]} df = pd.DataFrame(data) spike_cols = [col for col in df.columns if 'spike' in col] print(list(df.columns)) print(spike_cols) Add solution
Best helpers
Wayne
+5
Abe bubush
+5
Kyle Carlson
+5
Myles
+5
Obachola
+5
Takje
+5
Trevorj
+5
David
+5
Mrgoon
+5
Mitsos
+5
Nuraxi
+5
Ahmed Masud
+5