python中的数据帧到文本文件

python中的数据帧到文本文件,python,pandas,Python,Pandas,我目前正在使用此代码:- print(df.to_csv(r'tweets.txt', header=None, index=None, sep=' ', mode='a')) 通过这个,我得到了文本文件中的所有列,但我只想要一列。有人知道我怎么做吗? 提前感谢只需再选择感兴趣的列: print(df[col_of_interest].to_csv(r'tweets.txt', header=None, index=None, sep=' ', mode='a')) 通过执行df[col\u

我目前正在使用此代码:-

print(df.to_csv(r'tweets.txt', header=None, index=None, sep=' ', mode='a'))
通过这个,我得到了文本文件中的所有列,但我只想要一列。有人知道我怎么做吗?
提前感谢

只需再选择感兴趣的列:

print(df[col_of_interest].to_csv(r'tweets.txt', header=None, index=None, sep=' ', mode='a'))
通过执行
df[col\u of_interest]
操作,您只需选择将返回
系列的单列,如果您想要数据帧,请使用双方括号:

print(df[[col_of_interest]].to_csv(r'tweets.txt', header=None, index=None, sep=' ', mode='a'))
您还可以将单个列表项传递给param

print(df.to_csv(r'tweets.txt', header=None, index=None, sep=' ', mode='a', columns=['col_of_interest']))