Removing brackets at dataframe or list [Python]
Question:
I’m tryin to remove bracket and split a part of a string that duplicated in column 0 when I create a new DF
or list
with this two columns from a csv:
indice Password Status Priority Arrive time Call time Begin End Standby Time %TME TME time_raw
0 1 NB0001 Atendida Normal 28/11/2022 08:01 08:02:24 08:02:42 08:13:54 00:01:19 100,00% 00:01:19 00:00:02
1 2 NB0002 Atendida Normal 28/11/2022 08:01 08:03:54 08:04:21 08:12:33 00:02:20 127,85% 00:01:49 00:00:03
2 3 NB0003 Atendida Normal 28/11/2022 08:03 08:03:59 08:05:23 08:22:21 00:02:11 112,29% 00:01:57 00:00:04
3 4 NB0004 Atendida Normal 28/11/2022 08:15 08:04:19 08:05:15 08:13:59 00:01:12 68,25% 00:01:46 00:00:05
4 5 NB0005 Atendida Normal 28/11/2022 08:16 08:18:46 08:20:21 08:27:19 00:02:51 144,18% 00:01:59 00:00:06
df = ['arrive time'] =
28/11/2022 08:01
28/11/2022 08:01
28/11/2022 08:03
28/11/2022 08:15
28/11/2022 08:16
28/11/2022 08:17
28/11/2022 08:20
and
df2 = ['standby time'] =
00:01:19
00:02:20
00:02:11
00:01:12
00:02:51
00:06:22
00:06:55
I tried different ways to bring it and append the two columns in one DF
or list
like code below with one column for DF1
and DF2
at the same DF
or list
squares = [[]]
x = dados[["arrive time"]]
y = dados[["index"]]
date_arrive = dados['arrive time']
date_arrive = pd.to_datetime(date_arrive, dayfirst=True)
for i in range(len(x)):
TE = x["wait time"]
hours = str(x["arrive time"][i]).replace(" ","").split(":")
hoursTMEX = str(x['arrive time'][i]).replace(" ","").split(":")
TMEX = int(hours[0].replace("0 ","")) * 3600 + int(hours[1]) * 60 + int(hours[2].replace("n1 00",""))
TEX = int(hoursTMEX[0].replace("0 ","")) * 3600 + int(hoursTMEX[1]) * 60 + int(hoursTMEX[2].replace("n1 00",""))
squares.append([[date_arrive], [TEX]])
data_df = pd.DataFrame(squares)
data_df = data_df
RESULT (Code above):
0 None None
1 [[2022-11-28 08:01:00, 2022-11-28 08:01:00, 20... [79]
2 [[2022-11-28 08:01:00, 2022-11-28 08:01:00, 20... [140]
3 [[2022-11-28 08:01:00, 2022-11-28 08:01:00, 20... [131]
4 [[2022-11-28 08:01:00, 2022-11-28 08:01:00, 20... [72]
I need it like that:
0| None | None |
1| 2022-11-28 08:01:00| 79 |
2| 2022-11-28 08:01:00| 140 |
3| 2022-11-28 08:01:00| 131 |
4| 2022-11-28 08:01:00| 72 |
...
PS: I tried to append this two infos squares.append([[date_arrive], [TEX]])
out of the loop but returns me only one line, probabilly I’m not going right way.
I’ll be pleased if someone could help me to remove the repeated string in column 0 and help me remove these brackets in the two columns.
Answers:
The solution I founded is when Appending
the list like that:
squares.append([[date_arrive], [TEX]])
was missing [i] iterator from loop (for)
squares.append([date_arrive[i], TEX])
I’m tryin to remove bracket and split a part of a string that duplicated in column 0 when I create a new DF
or list
with this two columns from a csv:
indice Password Status Priority Arrive time Call time Begin End Standby Time %TME TME time_raw
0 1 NB0001 Atendida Normal 28/11/2022 08:01 08:02:24 08:02:42 08:13:54 00:01:19 100,00% 00:01:19 00:00:02
1 2 NB0002 Atendida Normal 28/11/2022 08:01 08:03:54 08:04:21 08:12:33 00:02:20 127,85% 00:01:49 00:00:03
2 3 NB0003 Atendida Normal 28/11/2022 08:03 08:03:59 08:05:23 08:22:21 00:02:11 112,29% 00:01:57 00:00:04
3 4 NB0004 Atendida Normal 28/11/2022 08:15 08:04:19 08:05:15 08:13:59 00:01:12 68,25% 00:01:46 00:00:05
4 5 NB0005 Atendida Normal 28/11/2022 08:16 08:18:46 08:20:21 08:27:19 00:02:51 144,18% 00:01:59 00:00:06
df = ['arrive time'] =
28/11/2022 08:01
28/11/2022 08:01
28/11/2022 08:03
28/11/2022 08:15
28/11/2022 08:16
28/11/2022 08:17
28/11/2022 08:20
and
df2 = ['standby time'] =
00:01:19
00:02:20
00:02:11
00:01:12
00:02:51
00:06:22
00:06:55
I tried different ways to bring it and append the two columns in one DF
or list
like code below with one column for DF1
and DF2
at the same DF
or list
squares = [[]]
x = dados[["arrive time"]]
y = dados[["index"]]
date_arrive = dados['arrive time']
date_arrive = pd.to_datetime(date_arrive, dayfirst=True)
for i in range(len(x)):
TE = x["wait time"]
hours = str(x["arrive time"][i]).replace(" ","").split(":")
hoursTMEX = str(x['arrive time'][i]).replace(" ","").split(":")
TMEX = int(hours[0].replace("0 ","")) * 3600 + int(hours[1]) * 60 + int(hours[2].replace("n1 00",""))
TEX = int(hoursTMEX[0].replace("0 ","")) * 3600 + int(hoursTMEX[1]) * 60 + int(hoursTMEX[2].replace("n1 00",""))
squares.append([[date_arrive], [TEX]])
data_df = pd.DataFrame(squares)
data_df = data_df
RESULT (Code above):
0 None None
1 [[2022-11-28 08:01:00, 2022-11-28 08:01:00, 20... [79]
2 [[2022-11-28 08:01:00, 2022-11-28 08:01:00, 20... [140]
3 [[2022-11-28 08:01:00, 2022-11-28 08:01:00, 20... [131]
4 [[2022-11-28 08:01:00, 2022-11-28 08:01:00, 20... [72]
I need it like that:
0| None | None |
1| 2022-11-28 08:01:00| 79 |
2| 2022-11-28 08:01:00| 140 |
3| 2022-11-28 08:01:00| 131 |
4| 2022-11-28 08:01:00| 72 |
...
PS: I tried to append this two infos squares.append([[date_arrive], [TEX]])
out of the loop but returns me only one line, probabilly I’m not going right way.
I’ll be pleased if someone could help me to remove the repeated string in column 0 and help me remove these brackets in the two columns.
The solution I founded is when Appending
the list like that:
squares.append([[date_arrive], [TEX]])
was missing [i] iterator from loop (for)
squares.append([date_arrive[i], TEX])