How to flatten a list of lists in python ?
Sample Data [[1,2], [1], [3,4]] Result Data [1,2,1,3,4] How to do? Method1. from itertools import chain sample_list = [[1, 2], [1], [3, 4]] # method1 result_list = list(chain(*sample_list)) print(result_list) #[1, 2, 1, 3, 4] Method2. from itertools import chain sample_list = [[1, 2], [1], [3, 4]] # method 2 result_list = list(chain.from_iterable(sample_list)) print(result_list) #[1, 2, 1, 3, 4]..
Change Dtypes Series of Pandas DataFrame to Dictionary
Sample Data - DataFrame group1 group2 key val 0 01 11 A 10 1 01 11 B 100 2 01 11 D 1000 3 02 12 A 10 4 02 12 C 1 5 02 12 B 100 6 03 13 D 1000 7 03 13 B 100 Result Data {'group1': 'object', 'group2': 'object', 'key': 'object', 'val': 'object'} How to Do? 1. Check DataFrame Column dtypes and type import pandas as pd sample_dict = {'group1':['01', '01', '01', '02', '02', '02', '03', '03'], 'group2'..