<jupyter_start><jupyter_text>from_dicthttps://stackoverflow.com/questions/18837262/convert-python-dict-into-a-dataframe<jupyter_code>import pandas as pd

data = {'row_1': [3, 2, 1, 0], 'row_2': ['a', 'b', 'c', 'd']}
df = pd.DataFrame.from_dict(data, orient='index', dtype = "category")
df
df = pd.DataFrame.from_dict(data, dtype = "category")
df
data = {'e1' : ['g3', 'g2', 'g1'], 'e2' : ['g2'], 'e3' : ['g3'], 'p1' : ['g1', 'g3']}
# sort values list 
new_data = {k: sorted(v) for k, v in data.items()}
# generate column names
maxv = max([len(v) for v in new_data.values()])
colnames = ['col'+str(i) for i in range(maxv)]

df = pd.DataFrame.from_dict(new_data, orient='index', columns=colnames)
df
maxv = max([len(v) for v in new_data.values()])
colnames = ['col'+str(i) for i in range(maxv)]
print(colnames)<jupyter_output>['col0', 'col1', 'col2']<jupyter_text>from dict for variable listhttps://stackoverflow.com/questions/50751184/pandas-dataframe-from-dictionary-of-list-valueshttps://stackoverflow.com/questions/46064760/create-a-dataframe-from-a-dictionary?noredirect=1&lq=1https://stackoverflow.com/questions/34997174/how-to-convert-list-of-model-objects-to-pandas-dataframeuse of stack  multi indexhttps://pandas.pydata.org/pandas-docs/stable/user_guide/advanced.html<jupyter_code>d = { '2017-09-01' : ['A', 'B'] , '2017-09-02' : ['C', 'D', 'E'] }

df = pd.DataFrame(
    [(k, val) for k, vals in d.items() for val in vals], 
    columns=['date', 'message']
)

df.join<jupyter_output><empty_output><jupyter_text>use categorical datatype in pandas  one hot encodinghttps://stackoverflow.com/questions/37292872/how-can-i-one-hot-encode-in-python  join on itself   pivotinghttps://pandas.pydata.org/pandas-docs/stable/user_guide/reshaping.htmlreshaping  merge with other dataframehttps://stackoverflow.com/questions/53645882/pandas-merging-101  convert dict to pandas dataframehttps://stackoverflow.com/questions/17839973/constructing-pandas-dataframe-from-values-in-variables-gives-valueerror-if-usi<jupyter_code>import pandas as pd

class ABC():
    
    def __init__(self):
        self._name = 'string'
        self._age = 10
        self._addr = 'highway'
    
    def as_dict(self): 
        return {
            'name' : [self._name],
            'age'  : [self._age],
            'addr' : [self._addr],
        }
    
    def as_scalar_dict(self): 
        return {
            'name' : self._name,
            'age'  : self._age,
            'addr' : self._addr,
        }


abc = ABC()
df = pd.DataFrame(abc.as_dict())
print(df)

df2 = pd.DataFrame(abc.as_scalar_dict(), index=[0])
print(df2)<jupyter_output>name  age     addr
0  string   10  highway
     name  age     addr
0  string   10  highway
{'fraction_non_alphanumeric': 0.16586804275709546, 'fraction_numerical': 0.03980833026170291, 'mean_word_length': 3.7447552447552446, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 9, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '409771', 'license': 'Apache-2.0', 'n_tokens_mistral': 1088, 'n_tokens_neox': 1008, 'n_words': 188, 'path': 'record_linkage/dataframe from item in various groups.ipynb', 'repo_name': 'sanjosh/machine_learning', 'size': '2713'}