Can you please help me?
I have two pandas dataframes and I need to extract every tenth value from the specific column from the first dataframe in a list. Then I need to create a new column in a second dataframe and put these values in this column. I also need my number of a row to match in both dataframes. Here is the code:
import numpy as np
import pandas as pd
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score
from sklearn.model_selection import cross_val_score
import matplotlib.pyplot as plt
# we will use random forest classifier as our classifier
forest_classifier=RandomForestClassifier(max_depth=4)
# reading in accelerometer data
train_time = pd.read_csv("https://courses.edx.org/assets/courseware/v1/b98039c3648763aae4f153a6ed32f38b/asset-v1:HarvardX+PH526x+3T2022+type@asset+block/train_time_series.csv", index_col=0)
train_labels = pd.read_csv("https://courses.edx.org/assets/courseware/v1/d64e74647423e525bbeb13f2884e9cfa/asset-v1:HarvardX+PH526x+3T2022+type@asset+block/train_labels.csv", index_col=0)
x = []
y = []
z = []
# making lists out of the x, y, z columns
for i in range(3, len(train_time), 10):
x.append(train_time.iloc[i]["x"])
y.append(train_time.iloc[i]["y"])
z.append(train_time.iloc[i]["z"])
print(z) # checking the list
# making new columns in train_labels file with the obtained lists
train_labels["x"] = pd.Series([x])
train_labels["y"] = pd.Series([y])
train_labels["z"] = pd.Series([z])
train_labels.head()
But I get the output, where the created columns have just the values of "NaN"
The output should be the dataframe with the created x, y, z columns, which have corresponding numbers of observations.