Reputation: 899
Im trying to convert an excel columns into a dataframe list separated by comma, Here is the excel sheet
that is the code I'm trying:
df=pd.read_excel('eng_test.xlsx',"Sheet1")
new_df = pd.DataFrame(df)
for column in new_df:
new_df2=new_df.apply(pd.Series)
new_df3=(new_df2.to_string())
new_df4=new_df3.split()
#print(new_df4)
I' m expecting the df be like this
df = pd.DataFrame(['This is my first sentence', 'This is a second sentence with more words'])
Upvotes: 4
Views: 1247
Reputation: 953
Although it is not clear what you really what to achieve a Dataframe with rows from Excel column or a list, you can do something like this using header=None
:
df=pd.read_excel('text_excel.xlsx', header=None)
print("\nDataframe: ")
print(df)
df_list = df.values.tolist()
print("\nList: ")
print(df_list)
With this you get the following output:
Dataframe:
0
0 'This is my first sentence'
1 This is a second sentence with more words
List:
[["'This is my first sentence'"], ['This is a second sentence with more words']]
Upvotes: 1