0

I have a series (saved as series in my code) and want to save its values into two different arrays using python. The first six values I want to save in an array called x, where:

series[0] = x[0,0], series[1] = x[0,1], series[2] = x[0,2], series[3] = x[0,3], series[4] = x[0,4], series[5] = x[0,5], series[6] = x[0,6].

Now switch to series[7] = y[0]. Then repeat and create a new row in x: series[8] = x[1,0], series[9] = x[1,1], series[10] = x[1,2], series[11] = x[1,3], series[12] = x[1,4], series[13] = x[1,5], series[14] = x[1,6]. Now switch to series[14] = y[1] and continue.

I have only been able to read in the .csv file and convert it from a dataframe to a series. I think this problem can be solved using nested for loops but have been unable to figure it out. Thank you for your help!

Python

import pandas as pd
import numpy as np 
import matplotlib.pyplot as plt
import matplotlib.dates as mdates

df = pd.read_csv("Data.csv")

series = df['totalBuildingEnergykW_EVERLY_HALL_BUILDING_ENERGY_EnergyMetric']

Series Snippet

1 Answer 1

1

It is a better idea to use df['Column_name'].tolist() function to get data from a dataframe's column into a list as this gives you data in list format.

import pandas as pd
import numpy as np 
df = pd.read_csv("File.csv")
L = df['column_name'].tolist() 
w, h = 6, 2;
Arr = [[0 for x in range(w)] for y in range(h)] 
for i,item in enumerate(L):
    if i<6 :
         Arr[0][i] = item
    else :
         Arr[1][i-6] = item
Sign up to request clarification or add additional context in comments.

2 Comments

That Arr line is how you intialize a multi_dimensional array
Thanks for your help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.