I am trying to save a pandas dataframe as .csv file. Currently my code looks like this:
with open('File.csv', 'a') as f: df.to_csv(f, header=False)
The saving works but the problem is that the lists in my dataframe are just compressed to [first,second,…,last] and all the entries in the middle are discarded. If I just look at the original dataframe all entries are there. Is there any way how I can convert the list to a string which contains all the elements (str(df) also discards the middle elements) or how I can save a full numpy array in a cell of a csv table?
Thank you for your help, Viviane
Advertisement
Answer
You can probably convert elements present in the list using join method.
example:
lst = ['Hello!','I','am', 'Pandas User','.'] strng = ' '.join(lst) print (strng)
hope this helps to you.