简体   繁体   中英

how can I sort certain values in one column of one csv file as a result of multiple csv file?

I'm new to use Python. I would like to handle 114 csv file as my simulation results. At this moment, I calculate average of each csv file and make one csv file. Based on above file, I want to extract only 4 values from below csv file.

Results/1a\001a.csv,3.729555644876643e-05,-8.489722306072623e-09,0.2189213009779949,1.8189734046014334e-08,0.21661787881258218,-2.55622256504202e-05,2.957845146641823e-06,0.005881073673178551,0.001028817803792101,0.20050853330394616,5.214465733076785e-06,0.19967684452546472,-0.0010047694830277378,inf,1.4841531644318505e-05,0.02490000000000206,0.020599999999999983,0.0060000003075623785,inf,8.809984745406528e-05,0.02490000000000206,0.020599999999999983,0.0060000003075623785
Results/1a\002a.csv,0.00044266393558895027,-4.871692086408956e-07,0.491797297872664,-1.4374768245601583e-05,0.48788925514981035,-0.00011101106735340776,5.3131821116074796e-05,0.02997964996383977,0.003919473465573261,0.4467310064440727,-0.0001537532334179777,0.4451642735022221,-0.005129463501241342,inf,6.396275140922866e-05,0.024800000000015338,0.02059999999999965,0.006439365934432054,inf,0.00020025575929075146,0.024800000000015338,0.02059999999999965,0.006439365934432054
Results/1a\003a.csv,0.0013688882649255905,-5.811439696558463e-07,0.7235505352349502,-1.841992502829627e-06,0.7188667004955674,-8.354410614115703e-05,0.00018602179959436254,0.06327359925790432,0.006802051121068685,0.6573219886196483,-5.361314096898339e-05,0.6554473776013993,-0.003483470537165227,inf,0.00013162281892988633,0.02469999999999655,0.020599999999999712,0.006037445347231759,inf,0.000297761205072387,0.02469999999999655,0.020599999999999712,0.006037445347231759
Results/1a\004a.csv,0.0029087011937919977,-6.223790450501293e-07,0.944839107407674,2.120875772647082e-05,0.9396578033827917,-0.00030080025961839215,0.00043332350911585326,0.103624137395163,0.009632247232105758,0.8662811882484165,-0.00040192890174102784,0.8641474385496596,-0.0018479810684538943,inf,0.00013347284255437153,0.02460000000000782,0.020599999999999594,0.0058108412768377365,inf,0.0003949692974612218,0.02460000000000782,0.020599999999999594,0.0058108412768377365
Results/1a\005a.csv,0.005111103180682736,-2.1135229634622883e-06,1.1645656717324973,3.726801334127048e-05,1.1589843566808042,-0.0003747348409265324,0.0008320027973329297,0.14826622143687557,0.012461695552911812,1.083837242606168,3.636550037486185e-05,1.0815461970970663,-0.0027228376349728053,inf,0.00016556367820564125,0.02449999999999286,0.020599999999999615,0.005855731524347499,inf,0.000498443717769948,0.02449999999999286,0.020599999999999615,0.005855731524347499

My result file is result_1a.csv. I tried to make csv file to dataframe and extract necessary values. However, it didn't work I guess because of below reason.

import pandas as pd
df = pd.read_table("result_1a.csv")
print(df)
df.info()

Please see below information.

[114 rows x 1 columns]
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 114 entries, 0 to 113
Data columns (total 1 columns):
dtypes: object(1)

1 column includes the following value[filename,u1u1,u2u2,u3u3,Mean,velocity, ....]. How can I extract only u1u1, u2u2,u3u3 values?

Actually, it would be great to divide 1 column into several column depending on each values. Is it possible to that in python?

Thanks to your helps in advance.

for your example:

import pandas as pd
df = pd.read_csv("result_1a.csv")

you can filter the mentioned values in the column ("col_name") with:

df_filtered = df[(df["col_name"]=='u1u1') | (df["col_name"]=='u2u2') | (df["col_name"]=='u3u3')]
df_filtered.index = df_filtered["col_name"]
df_filtered = df_filtered.drop(["col_name"], axis=1)
df_filtered = df_filtered.transpose()

The " | " marks a locigal or.

Best regards

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM