Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

how to apply 1nf dataframe in python

01
02
03
04
05
06
07
08
09
10
11
12
import pandas as pd
import numpy as np
 
df = pd.DataFrame({'Name': ['David', 'Glenn', 'Steve'], 'Subjects': [
                  ['English', 'Math'], ['Math'], ['Science', 'English']]})
 
lens = list(map(len, df['Subjects'].values))
 
res = pd.DataFrame({'Name': np.repeat(
    df['Name'], lens), 'Subject': np.concatenate(df['Subjects'].values)})
 
print(res)
Source by www.pythonpool.com #
 
PREVIOUS NEXT
Tagged: #apply #dataframe #python
ADD COMMENT
Topic
Name
1+1 =