Py学习  »  Manjunath K Mayya  »  全部回复
回复总数  3

你可以试试这个。

authors = ','.join(df['authors'].to_list())
with open('mycsv.csv', 'w', newline='') as myfile:
    myfile.write(authors)
3 年前
回复了 Manjunath K Mayya 创建的主题 » Python集以字符串形式存储在数据帧的列中

我认为在将数据帧转换为csv时,可以使用不同的分隔符。

import pandas as pd
df = pd.DataFrame(["{'Ramesh','Suresh','Sachin','Venkat'}"],columns=['set'])
print('Old df  \n', df)

df.to_csv('mycsv.csv', sep= ';', index=False)

new_df = pd.read_csv('mycsv.csv', sep= ';')
print('New df \n',new_df)

输出:

enter image description here

3 年前
回复了 Manjunath K Mayya 创建的主题 » Python——试图找出如何将两个列表的每个部分相乘

像这样使用列表理解

print([i * j for i in list1 for j in list2])

输出:

[12, 4, 36, 8, 6, 2, 18, 4, 21, 7, 63, 14]