Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use natural sort order when storing data log to csv #699

Closed
MichaelClerx opened this issue Feb 19, 2021 · 1 comment
Closed

Use natural sort order when storing data log to csv #699

MichaelClerx opened this issue Feb 19, 2021 · 1 comment
Labels

Comments

@MichaelClerx
Copy link
Member

Makes it easier to load multicell data without having to re-order CSV columns, see #695

@MbNicolas
Copy link

MbNicolas commented Feb 21, 2021

Here is the code I have used to sort the datalog in a natural way!
This is my original datalog in the csv file :
in :
import pandas as pd
df=pd.read_csv("propagation_normale.csv")
df.head()

out :

engine.time 0.membrane.V 1.membrane.V 10.membrane.V 100.membrane.V 101.membrane.V 102.membrane.V 103.membrane.V 104.membrane.V 105.membrane.V ... 90.membrane.V 91.membrane.V 92.membrane.V 93.membrane.V 94.membrane.V 95.membrane.V 96.membrane.V 97.membrane.V 98.membrane.V 99.membrane.V
0 0.0 -87.000000 -87.000000 -87.000000 -87.000000 -87.000000 -87.000000 -87.000000 -87.000000 -87.000000 ... -87.000000 -87.000000 -87.000000 -87.000000 -87.000000 -87.000000 -87.000000 -87.000000 -87.000000 -87.000000
1 0.1 -86.748009 -86.748009 -86.748009 -86.748009 -86.748009 -86.748009 -86.748009 -86.748009 -86.748009 ... -86.748009 -86.748009 -86.748009 -86.748009 -86.748009 -86.748009 -86.748009 -86.748009 -86.748009 -86.748009
2 0.2 -86.505295 -86.505295 -86.505295 -86.505295 -86.505295 -86.505295 -86.505295 -86.505295 -86.505295 ... -86.505295 -86.505295 -86.505295 -86.505295 -86.505295 -86.505295 -86.505295 -86.505295 -86.505295 -86.505295
3 0.3 -86.271400 -86.271400 -86.271400 -86.271400 -86.271400 -86.271400 -86.271400 -86.271400 -86.271400 ... -86.271400 -86.271400 -86.271400 -86.271400 -86.271400 -86.271400 -86.271400 -86.271400 -86.271400 -86.271400
4 0.4 -86.045898 -86.045898 -86.045898 -86.045898 -86.045898 -86.045898 -86.045898 -86.045898 -86.045898 ... -86.045898 -86.045898 -86.045898 -86.045898 -86.045898 -86.045898 -86.045898 -86.045898 -86.045898 -86.045898

And here is what I get after natural sorting :

in :
import pandas as pd
from natsort import natsorted #for natural sorting
name="reentree_3boucles.csv"
df=pd.read_csv(name) #lecture du fichier csv dans un dataframe
#natsorting dataframe according to column labels and reindexing
df1=df.reindex(natsorted(df.columns),axis=1)

#save dataframe to csv file
df1.to_csv('natsorted_'+name)
df1.head() #affichage des 5 premières lignes du dataframe

out :

0.membrane.V 1.membrane.V 2.membrane.V 3.membrane.V 4.membrane.V 5.membrane.V 6.membrane.V 7.membrane.V 8.membrane.V 9.membrane.V ... 495.membrane.V 496.membrane.V 497.membrane.V 498.membrane.V 499.membrane.V 500.membrane.V 501.membrane.V 502.membrane.V 503.membrane.V engine.time
0 -87.000000 -87.000000 -87.000000 -87.000000 -87.000000 -87.000000 -87.000000 -87.000000 -87.000000 -87.000000 ... -87.000000 -87.000000 -87.000000 -87.000000 -87.000000 -87.000000 -87.000000 -87.000000 -87.000000 0.0
1 -86.748009 -86.748009 -86.748009 -86.748009 -86.748009 -86.748009 -86.748009 -86.748009 -86.748009 -86.748009 ... -86.748009 -86.748009 -86.748009 -86.748009 -86.748009 -86.748009 -86.748009 -86.748009 -86.748009 0.1
2 -86.505295 -86.505295 -86.505295 -86.505295 -86.505295 -86.505295 -86.505295 -86.505295 -86.505295 -86.505295 ... -86.505295 -86.505295 -86.505295 -86.505295 -86.505295 -86.505295 -86.505295 -86.505295 -86.505295 0.2
3 -86.271400 -86.271400 -86.271400 -86.271400 -86.271400 -86.271400 -86.271400 -86.271400 -86.271400 -86.271400 ... -86.271400 -86.271400 -86.271400 -86.271400 -86.271400 -86.271400 -86.271400 -86.271400 -86.271400 0.3
4 -86.045898 -86.045898 -86.045898 -86.045898 -86.045898 -86.045898 -86.045898 -86.045898 -86.045898 -86.045898 ... -86.045898 -86.045898 -86.045898 -86.045898 -86.045898 -86.045898 -86.045898 -86.045898 -86.045898 0.4

And now the csv output is fine for plotting out of myokit!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants