OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Renaming column names in lists generated by a function in Python

  • Thread starter Thread starter Jon Z
  • Start date Start date
J

Jon Z

Guest
I am using PIconnect to pull data from a server. It iterates through a list of points and returns a list with a column name of the summary method (AVERAGE in this case). When I run the code below I end up with dataframe that has 300 columns all named Average. I would love to know if I can change those columns names to the point name in my script.

Code:
import pandas as pd
import PIconnect as PI
from PIconnect.PIConsts import SummaryType, TimestampCalculation

with PI.PIServer()as server:
   points = server.search('WTG*_AI_IN_TempA*')
   data = [point.summaries('5/14/2024','6/1/2024', '10m', SummaryType.AVERAGE, time_type=TimestampCalculation.EARLIEST_TIME)
   for point in points]
   data2 = pd.concat(data, axis = 1)

When this runs here are the variables data - List - Size 309 - Values are all Dataframes data2 - DataFrame - Size (2448,309), All Columns are labeled AVERAGE.

Thanks

Jon

I tried breaking the loop in different spots to used pandas to rename the column, but nothing has worked.
<p>I am using PIconnect to pull data from a server. It iterates through a list of points and returns a list with a column name of the summary method (AVERAGE in this case). When I run the code below I end up with dataframe that has 300 columns all named Average. I would love to know if I can change those columns names to the point name in my script.</p>
<pre><code>import pandas as pd
import PIconnect as PI
from PIconnect.PIConsts import SummaryType, TimestampCalculation

with PI.PIServer()as server:
points = server.search('WTG*_AI_IN_TempA*')
data = [point.summaries('5/14/2024','6/1/2024', '10m', SummaryType.AVERAGE, time_type=TimestampCalculation.EARLIEST_TIME)
for point in points]
data2 = pd.concat(data, axis = 1)
</code></pre>
<p>When this runs here are the variables
data - List - Size 309 - Values are all Dataframes
data2 - DataFrame - Size (2448,309), All Columns are labeled AVERAGE.</p>
<p>Thanks</p>
<p>Jon</p>
<p>I tried breaking the loop in different spots to used pandas to rename the column, but nothing has worked.</p>
 

Latest posts

S
Replies
0
Views
1
Safwan Aipuram
S
Top