akshay akshay - 2 months ago 7
Python Question

Get minimum number column wise in a multidimensional Pandas DataFrame - Python

I am new to Pandas. I am trying to get the minimum number column-wise. So these are the steps I have followed:


  1. I read the files from CSV files using

    data = [pd.read_csv(f, index_col=None, header=None) for f in temp]

  2. Then added it to another data frame
    flow = pd.DataFrame(data)
    , making it "3d" data-frame.



So,
data
has
[128 rows x 14 columns] * 60 samples
with out
index_col
and
header


One of the samples is:

[ 0 1 2 3 4 5 6 7 8 9 10 11 12 13
0 3985.1 4393.3 4439.5 3662.1 5061.0 3990.8 4573.8 4036.9 4717.9 4225.6 4638.5 4157.9 4496.4 4007.7
1 3998.5 4398.5 4447.2 3660.0 5062.6 3986.7 4573.3 4045.1 4733.8 4238.5 4650.3 4167.2 4509.2 4022.6
2 3995.4 4397.9 4442.1 3659.5 5058.5 3987.2 4569.7 4039.5 4724.1 4234.9 4645.6 4161.5 4506.2 4014.9
3 3985.1 4396.9 4432.3 3660.0 5054.9 3988.2 4568.2 4037.9 4719.0 4230.3 4632.3 4150.8 4500.5 4004.1
4 3985.1 4391.3 4428.2 3661.5 5057.9 3987.2 4570.8 4044.6 4731.3 4236.9 4631.8 4151.8 4503.1 4005.6
5 3991.3 4391.8 4430.8 3662.6 5059.5 3987.7 4572.8 4044.6 4730.8 4237.4 4639.5 4157.4 4507.2 4009.7
6 3989.7 4396.9 4436.9 3661.5 5057.4 3987.7 4571.3 4035.4 4716.9 4230.3 4641.0 4156.9 4505.1 4010.8
7 3983.6 4392.8 4435.4 3660.0 5056.9 3987.2 4570.8 4032.8 4719.5 4227.7 4634.4 4153.8 4497.4 4008.2
8 3983.1 4388.7 4428.7 3661.5 5056.9 3987.7 4571.8 4041.0 4728.2 4231.8 4631.3 4154.4 4499.0 4004.6
9 3988.2 4395.9 4433.3 3662.1 5057.9 3987.7 4572.3 4040.5 4720.5 4231.3 4636.9 4154.9 4503.1 4005.1
10 3988.7 4398.5 4439.0 3660.0 5060.0 3986.7 4572.3 4032.3 4710.3 4225.1 4640.5 4154.9 4497.4 4008.2
11 3983.6 4391.3 4434.4 3661.0 5059.0 3988.7 4570.3 4041.0 4724.6 4235.4 4642.6 4163.1 4499.5 4010.8
12 3984.1 4388.7 4432.8 3664.1 5058.5 3991.8 4574.4 4051.8 4740.5 4245.1 4645.1 4170.8 4507.7 4014.4
13 3986.7 4390.8 4432.8 3664.1 5057.9 3991.3 4583.1 4043.1 4724.6 4231.8 4642.1 4161.5 4505.6 4012.8
14 3984.6 4395.4 4433.8 3661.5 5059.0 3991.3 4583.1 4036.9 4713.8 4222.1 4641.0 4157.4 4503.1 4010.8
15 3989.2 4400.5 4440.0 3661.0 5066.7 3994.4 4579.5 4045.1 4732.8 4233.8 4648.2 4170.3 4509.2 4016.4
16 3990.8 4394.4 4437.4 3661.5 5071.8 3996.4 4580.5 4045.1 4738.5 4239.5 4650.3 4171.3 4509.7 4016.4
17 3979.0 4383.6 4426.7 3660.0 5065.6 3995.4 4577.4 4034.4 4715.4 4228.2 4643.6 4158.5 4504.6 4005.1
18 3972.8 4383.1 4426.2 3660.0 5057.9 3991.8 4569.7 4034.4 4712.3 4228.2 4639.5 4157.9 4502.6 3999.0
19 3982.6 4386.7 4430.3 3661.5 5055.9 3987.2 4568.7 4045.6 4737.4 4243.1 4641.0 4166.7 4504.1 4007.7
20 3990.3 4389.7 4432.3 3661.5 5059.5 3989.7 4571.8 4047.2 4740.5 4245.1 4647.2 4169.2 4506.2 4014.9
21 3989.2 4392.8 4435.4 3661.0 5066.7 3996.9 4573.8 4035.9 4713.8 4232.3 4650.3 4166.7 4505.6 4014.4
22 3989.7 4391.8 4435.4 3661.5 5069.7 3997.4 4571.8 4035.4 4711.8 4231.3 4647.2 4167.7 4507.7 4017.4
23 3990.8 4389.7 4432.8 3660.0 5069.2 3996.9 4569.2 4044.6 4734.9 4237.9 4646.2 4168.7 4509.7 4020.0
24 3988.7 4393.3 4434.9 3659.0 5070.3 4000.5 4570.8 4041.0 4725.6 4232.8 4648.2 4166.7 4504.6 4016.4
25 3990.3 4397.9 4440.0 3661.0 5065.6 3997.9 4571.8 4039.0 4713.8 4230.8 4650.3 4169.7 4506.7 4019.0
26 3990.8 4396.4 4437.4 3662.1 5057.9 3988.7 4572.3 4045.1 4729.2 4236.4 4648.2 4169.7 4509.2 4022.6
27 3984.6 4385.1 4425.6 3661.5 5056.4 3990.8 4577.4 4041.5 4727.2 4231.8 4641.5 4158.5 4495.4 4010.3
28 3983.6 4381.0 4424.6 3662.1 5057.4 3999.5 4585.1 4037.4 4716.9 4229.7 4641.5 4157.4 4491.8 4006.2
29 3991.8 4391.3 4434.9 3662.1 5056.9 4000.0 4588.7 4040.5 4723.1 4234.4 4647.7 4167.7 4503.1 4017.4
.. ... ... ... ... ... ... ... ... ... ... ... ... ... ...
98 3988.2 4372.3 4424.1 3662.1 5040.5 3989.2 4585.6 4033.3 4719.0 4233.3 4647.2 4163.6 4502.1 4011.8
99 3993.8 4382.1 4429.2 3660.5 5042.1 3988.2 4590.3 4045.1 4737.4 4255.9 4659.0 4176.9 4514.4 4021.5
100 3992.8 4384.1 4430.3 3661.0 5041.0 3989.7 4601.5 4039.5 4733.3 4264.1 4663.1 4186.2 4512.3 4023.6
101 3988.2 4374.9 4424.6 3663.6 5040.0 3991.3 4601.0 4028.7 4719.0 4247.7 4654.9 4171.8 4505.1 4017.4
102 3989.7 4374.9 4427.2 3662.1 5040.5 3990.8 4590.3 4033.3 4716.9 4234.4 4654.4 4168.7 4508.7 4015.9
103 3987.2 4372.3 4428.7 3660.5 5036.4 3988.2 4585.1 4035.9 4719.5 4231.8 4651.3 4171.3 4504.6 4012.8
104 3979.5 4365.6 4421.5 3662.1 5030.3 3984.1 4586.2 4030.3 4717.4 4229.7 4641.0 4158.5 4491.8 4005.6
105 3982.1 4372.8 4420.5 3662.1 5032.3 3974.9 4586.2 4034.4 4719.0 4233.8 4640.0 4155.4 4495.4 4006.2
106 3987.7 4380.0 4427.7 3659.5 5037.9 3973.8 4584.1 4039.0 4720.5 4241.0 4644.1 4165.1 4509.2 4010.8
107 3987.2 4374.4 4428.7 3662.6 5039.5 3982.6 4585.1 4034.4 4719.0 4233.3 4641.5 4158.5 4506.7 4007.7
108 3982.6 4370.8 4420.0 3664.1 5036.9 3982.6 4587.7 4034.9 4724.1 4228.7 4639.0 4150.8 4495.4 4000.5
109 3979.0 4372.3 4414.4 3658.5 5029.2 3971.8 4580.0 4037.4 4723.6 4233.8 4639.5 4154.9 4492.8 3997.4
110 3979.0 4374.4 4418.5 3658.5 5027.7 3970.3 4571.3 4029.7 4712.3 4225.6 4640.0 4155.4 4496.9 3998.5
111 3986.2 4381.0 4428.2 3663.1 5037.4 3980.5 4580.0 4025.6 4705.1 4217.9 4643.6 4157.9 4504.1 4003.1
112 3991.3 4383.6 4430.3 3661.5 5042.6 3985.6 4585.6 4027.2 4708.7 4225.6 4644.6 4166.7 4508.2 4007.2
113 3983.6 4378.5 4432.8 3659.0 5034.4 3976.9 4573.8 4032.8 4725.6 4236.9 4643.6 4165.6 4504.1 4005.1
114 3976.4 4380.0 4443.6 3661.0 5028.2 3968.7 4572.8 4037.4 4735.4 4247.2 4649.7 4168.2 4507.7 4008.2
115 3973.8 4378.5 4441.5 3661.5 5033.3 3974.4 4585.6 4028.2 4713.3 4236.9 4650.8 4170.8 4508.2 4004.1
116 3971.8 4370.3 4431.8 3661.0 5036.4 3983.6 4588.7 4019.0 4696.4 4212.3 4639.0 4159.0 4496.9 3991.8
117 3972.3 4371.8 4437.4 3661.0 5031.3 3982.1 4585.1 4032.3 4720.5 4218.5 4637.4 4155.9 4496.9 3994.9
118 3973.8 4379.0 4444.1 3660.5 5032.3 3980.0 4587.2 4041.0 4730.8 4236.9 4646.7 4166.7 4506.2 4006.7
119 3982.1 4385.1 4447.2 3661.5 5040.5 3984.1 4586.7 4024.6 4708.2 4230.3 4648.2 4168.7 4506.7 4010.3
120 3991.3 4390.8 4452.8 3663.1 5043.1 3985.1 4576.4 4019.0 4710.8 4228.2 4650.3 4168.7 4505.6 4011.8
121 3989.2 4386.7 4451.3 3660.5 5041.0 3981.5 4568.2 4032.3 4733.3 4237.9 4657.4 4172.8 4508.2 4011.3
122 3983.6 4384.1 4448.7 3658.5 5040.0 3982.6 4574.4 4036.9 4730.8 4237.4 4656.4 4172.3 4505.6 4008.7
123 3987.7 4391.3 4455.4 3661.0 5038.5 3984.6 4585.6 4029.7 4716.4 4231.3 4655.4 4171.3 4504.1 4012.8
124 3990.8 4392.8 4460.0 3660.0 5038.5 3983.6 4583.1 4026.2 4714.4 4231.3 4656.9 4172.3 4506.2 4013.8
125 3988.7 4390.8 4456.4 3657.9 5040.0 3984.6 4576.4 4025.1 4715.9 4231.3 4651.8 4167.2 4505.1 4012.8
126 3990.3 4393.8 4455.9 3659.0 5040.0 3983.1 4577.4 4026.7 4720.5 4231.8 4647.2 4167.2 4505.6 4018.5
127 3988.2 4392.8 4453.3 3660.0 5040.5 3976.9 4581.5 4033.8 4732.8 4235.4 4649.2 4170.8 4506.2 4015.9

[128 rows x 14 columns]]


I am trying to get the minimum number column-wise for every sample. How should I do it?

I tried using
min()
, by doing
data[0][0].min()
but I get the following as the output:

[[ 3985.1 4393.3 4439.5 ..., 4157.9 4496.4 4007.7]
[ 3998.5 4398.5 4447.2 ..., 4167.2 4509.2 4022.6]
[ 3995.4 4397.9 4442.1 ..., 4161.5 4506.2 4014.9]
...,
[ 3988.7 4390.8 4456.4 ..., 4167.2 4505.1 4012.8]
[ 3990.3 4393.8 4455.9 ..., 4167.2 4505.6 4018.5]
[ 3988.2 4392.8 4453.3 ..., 4170.8 4506.2 4015.9]]


It's same as the sample. I don't know what's the problem here.

Answer

I think you need:

print (data[0].min(axis=1))
0      3662.1
1      3660.0
2      3659.5
3      3660.0
4      3661.5
5      3662.6
6      3661.5
7      3660.0
8      3661.5
9      3662.1
10     3660.0
11     3661.0
12     3664.1
13     3664.1
14     3661.5
15     3661.0
...
...

Maybe beter is omit flow = pd.DataFrame(data) and use:

data = [pd.read_csv(f, index_col=None, header=None) for f in temp]

mins = [df.min(axis=1) for df in data[0]]
print (mins[0])
print (mins[1])