The steps to read a data set in PyCharm include: creating a project and importing NumPy; using the loadtxt() function to load the data set, specifying the path and delimiter; checking the data shape; using indexes to access data values, as shown in Chapter 1 One row and first column; save the dataset using the savetxt() function.
How to read the data set in PyCharm
If you want to read the data set in PyCharm, you can use The following steps:
1. Create a project
2. Import NumPy
<code class="python">import numpy as np</code>
3. Load the dataset
loadtxt()
function data set. This function accepts path or file name as parameter. <code class="python">data = np.loadtxt('path/to/dataset.csv', delimiter=',')</code>
Where:
path/to/dataset.csv
is the path to the dataset file. delimiter
Specifies the character (comma in this example) that delimits data set values. 4. Check the data
shape
property ( Number of rows and columns): <code class="python">print(data.shape)</code>
5. Accessing data
<code class="python">first_row = data[0, :]</code>
<code class="python">first_column = data[:, 0]</code>
6. Save the data set
savetxt()
function: <code class="python">np.savetxt('new_dataset.csv', data, delimiter=',')</code>
The above is the detailed content of How to read data set in pycharm. For more information, please follow other related articles on the PHP Chinese website!