1

I currently have an excel file that is in this format:

PS               PSX1         PSX2         PSX3        PSX4
              I   P   V    I   P   V    I   P   V    I   P   V
States
Idle          #   #   #    #   #   #    #   #   #    #   #   #
Data=Addr(R)  #   #   #    #   #   #    #   #   #    #   #   #
Data=Addr(W)  #   #   #    #   #   #    #   #   #    #   #   # 
.             .   .   .    .   .   .    .   .   .    .   .   .
.             .   .   .    .   .   .    .   .   .    .   .   . 

When I try importing it as a pandas data frame it adds column names to give each one a name instead of just the four PSX1, PSX2, PSX3, and PSX4. It also adds NaN's in empty spaces. This becomes a problem when I try to graph it, I get an error saying "Empty 'DataFrame': no numeric data to plot". Is there a way to skip importing as a pandas data frame and just plot it straight after reading it in as an excel file?

I want the graph to be 4 lines (one for each power supply), and I only care about the P column with the x-axis being the different states. I am new to matplotlib and python in general. Any help is appreciated.

1 Answer 1

1

Use pandas to clean your data. Depending on your data this can be achieved in different ways. You can use pandas built-in functions:

your_dataframe_here.dropna(inplace=True) 

This will delete all NaN values, however, this is not an optimal approach. You should rather replace the NaN values with an appropriate value, either an outlier or the mean of closest values.

your_dataframe_here.fillna(value=-99999, inplace=True)

This will create outliers, however, if there are a large quantity of NaN values you should replace with the mean for best results.

your_dataframe_here.fillna(value=df['target_here'].mean())

or for non targeted:

your_dataframe_here.fillna(value=df.mean())

After cleaning your data you should separate your features and plot them appropriately. Also, the column names were added because the panda's library requires them. You can change them to how you see fit:

your_dataframe_here.columns = ['your_column_name', 'your_column_name']

Ensure that the size of your list matches the number of columns in your data frame. Finally, to strictly access the 'P' column, you can subset your data frame, for example:

your_P_set = your_data_frame['P']
Sign up to request clarification or add additional context in comments.

Comments

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.