DataFrame is difficult. I'm worried about the next problem.
--Store list1 and list2 in index 0 and index 1? --A pair where the indexes of list1 and list2 are aligned?
My idea is "I want to know Alice 's height ". This says, "Oh, you should pair Alice and Alice's height!"
In the following, write down from the two arrays to writing the file via DataFrame.
import pandas as pd
list1 = ['Alice', 'Bob', 'Charlie']
list2 = ['165', '175', '180']
dim2list = [[list1[i], list2[i]] for i in range(len(list1))]
df = pd.DataFrame(dim2list, columns=['Name', 'Length'])
df.to_csv('output.csv', index=False, header=True)
output.csv
Name,Length
Alice,165
Bob,175
Charlie,180
import pandas as pd
list1 = ['Alice', 'Bob', 'Charlie']
list2 = ['165', '175', '180']
dim2list = [[list1[i], list2[i]] for i in range(len(list1))]
df = pd.DataFrame(dim2list, columns=['Name', 'Length'])
df.to_csv('output.txt', sep='\t', index=False, header=True)
output.txt
Name Length
Alice 165
Bob 175
Charlie 180
Recommended Posts