Here an article on you can add to a column in the soame column wth Numpy and Panda’s lines:
Add lines to a column in the same colorumn
When together with Binance cryptocurrence data, it can can be difficult to the process. A comoon problem is if we have to carry outmated processes for the Data, e.g. B. adding new functions or lines to existing colorumns.
In this article we we will to add a column in the same wth Numpy and Panda’s lines.
Whats of the against columns?
Before we immerse in the solution, wequikly discuss it with what lines instead of columns. In most cases, cryptocurrency is stored in a 1-dimensional array (e.g. Numpy), with each line a single observation or sample. Adding a new column to that array can be as a new element at the end of the array.
Solution: Use of loops
Wen here with lata records, howver, we may have a carry out processes in all lines in a certain. In such cases, thee of loops is an effective to add new lines to the same column.
Here is a step-by-step solution:
`Python
Import pandas as a PD
Import nump as an NP
Binance data convert to Pandas Dataframe and Numpy Array
df = pd.dataTAframe ({'price': [100, 200, 300]})
Replice your data won'
Array = np.array ([1, 2, 3])
replace your data
Define Column index (0 based)
Col_index = 0
Initialize an empty list
new_rows = []
Cross every line in the Data (or array)
For I, walue in list (DF [Col_index]):
Add a new line to the list
new_row = {
'Price': DF [Col_index] [i] + np.random.uniform (-0.1, 0.1)
}
new_rows.append (new_row)
Sletting the new lines with the original data frame (or the array)
df.loc [:, Col_index] = pd.concat (new_rows, Ignore_index =tolist) .toolist ())
In this solution:
- We go throg each lyne in the specified column With “enumerates”
- For each line wead a new line to the “New_rows” list.
- We are available Pandas’ Concat ()`function to chained
Note: In the solution of it is assumed that information from the 1-dimensional array (e.g. Numpy). If you have information from the different format, you can have a solution according.
By using loops to add lines at theme time, we can can efficiated process lorge data and cardy outtomatated processs of process.