Issue
import pandas as pd
data = {'product_name': ['laptop,computer', 'printer,table', 'tablet,mobile', 'desk', 'chair,table'],
'price': [1200, 150, 300, 450, 200]
}
df_merge = pd.DataFrame(data)
I want to print data by using for loop 1st it should come laptop then computer then printer and so on. for example- enter image description here
I tried below lines of code but not getting what I want.
for i in (df_merge.product_name):
print(i)
Solution
USING FOR LOOP Code:
for i in (df_merge.product_name):
for s in i.split(','):
print(s)
Output;
laptop
computer
printer
table
tablet
mobile
desk
chair
table
Answered By - Stackpy
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.