【发布时间】:2017-08-16 12:28:36
【问题描述】:
我对 python 非常陌生,当我尝试在我的 excel 列中显示由唯一值创建的数据框时遇到了一个问题。
所以发生的事情是我尝试写“aa”我得到
[u'a' u'b' u'c' u'd' u'e' u'f']
当我想要的是
a, b, c, d, e, f
甚至
[a,b,c,d,e,f]
以更直接的为准。我的想法是,由于我使用的是str(),因此它会按原样使用数据框,但是,如果我在编写它时不包括str(),我会得到
∞*
p!`!@‹!@˛
作为输出...
这是我的代码:
df = pd.read_excel(open('/Users/keatonmaclean/Desktop/abcc.xlsx','rb'), sheetname='Sheet1')
# Set ipython's max row display
pd.set_option('display.max_row', 1000)
# Set iPython's max column width to 50
pd.set_option('display.max_columns', 50)
df.columns = df.iloc[0]
df = df[1:]
aa = str(df.loc[:,"Supplier"].unique())
#bb = str(df.loc[:,"CT #"].unique())
#cc = str(df.loc[:,"CT DESC"].unique())
#dd = str(df.loc[:,"CT START"].unique())
#ee = str(df.loc[:,"CT END"].unique())
import os.path
save_path = '/Users/keatonmaclean/Desktop/'
#name_of_file = raw_input("What is the name of the file: ")
name_of_file = "test"
completeName = os.path.join(save_path, name_of_file+".txt")
file1 = open(completeName, "w+")
toFile = aa
file1.write(toFile)
file1.close()
【问题讨论】:
标签: python excel pandas text unique