i have been working with this explode command. please here is my code fyr.
import pandas as pd
import os
os.getcwd()
os.chdir('C:/Users/nick/Documents/Python') # NOTE csv_filepath
df= pd.read_excel('output1.xlsx', usecols=['PartNumber', 'RefList'], index_col=False)
print(df.explode('RefList'))
file_name ='output2.xlsx'
df.to_excel(file_name)
Input file data // output1.xlsx
| PartNumber | RefList |
|---|---|
| ram | apple,orange |
| ravi | banan,pinapple |
receiving output data // output2.xlsx "same" i don't know where iam making a mistake.
| PartNumber | RefList |
|---|---|
| ram | apple,orange |
| ravi | banan,pinapple |
if I try to work with this below code it works
import pandas as pd
import numpy as np
df = pd.DataFrame({'animals': [['koala', 'kangaroo', 'echidna'],
['sloth', 'alpaca'],
['zebra', 'lion', 'baboon']],
'diet': [['herbivorous', 'herbivorous', 'carnivorous'],
['omnivorous', 'herbivorous'],
['herbivorous', 'carnivorous', 'omnivorous']],
'country': ['Australia', 'Peru', 'Kenya']})
print`(df)`
I have work with explode command not working. try to compile it with .data frame it works fine. if i call a excel or csv file not working.
Example
df:
Code
output:
then use following code