Combine Two Lists In Python In Dataframe With File Name Added In One Column And Content In Another
I have a list of files in a folder in my system file_list= ['A', 'B', 'C'] I Have read the files using a for loop and have obtained content which is as follows A = ['A1', 'B1', 'C
Solution 1:
Try this
import pandas as pd
data = list(zip((A, B, C), file_list))
df = pd.DataFrame(data, columns=['Content', 'Name'])
df = df.explode('Content')
print(df)
Output:
Content Name
0 A1 A
0 B1 A
0 C1 A
1 E1 B
1 F1 B
2 NaN C
Post a Comment for "Combine Two Lists In Python In Dataframe With File Name Added In One Column And Content In Another"