我对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()
我认为您需要} 或^{} :
DataFrame
或Series
构造函数和^{或者如果需要一列:
但如果需要,可以从所有唯一值创建文件^{} 函数
unique
。你知道吗但是,如果每列的唯一值长度不同,则得到
NaN
s,并且在输出中NaN
s被替换为空空间。你知道吗相关问题 更多 >
编程相关推荐