0

Need to plot a comparision graph to check which is better between model 2 and model3.

source is data is extracted from json file to macros excel file using power query.

I am getting error TypeError: no numeric data to plot

this is the details of df

df1.info()
out:<class 'pandas.core.frame.DataFrame'>
RangeIndex: 7513 entries, 0 to 7512
Data columns (total 4 columns):
#   Column  Non-Null Count  Dtype 
---  ------  --------------  ----- 
0   Name    7513 non-null   object
1   Model2  7513 non-null   object
2   Model3  7513 non-null   object
3   Manual  7513 non-null   object
dtypes: object(4)
memory usage: 234.9+ KB

this is the dataframe i want to plot for comparison between model2 with model3

df1

        Name    Model2  Model3  Manual
1   WH02_Met1   522.8   5228.6  0000.0
2   WH02_Met2   5229    5229    0000.0
3   WH02_Met3   5229.1  5229.1  0000.0
4   WH02_Met4   5229.5  5229.5  0000.0
... ... ... ... ...
7508    WH1_Met5    0000.0  0000.0  2651.4
7509    WH1_Met6    0000.0  0000.0  2651.4
7510    WH1_Met7    0000.0  0000.0  2651.4
7511    WH1_Met8    0000.0  0000.0  2651.4
7512    WH1_Met9    0000.0  0000.0  0000.0
7513 rows × 4 columns

here i checked the type

df1.dtypes

Name      object
Model2    object
Model3    object
Manual    object
dtype: object
df1.apply(pd.to_numeric, errors='ignore')
df1 = df1.infer_objects()
df1.dtypes
Name      object
Model2    object
Model3    object
Manual    object
dtype: object
df1[['Model2', 'Model3']] = df1[['Model2', 'Model3']].astype(float)
ValueError: could not convert string to float: 'Model2'

Community
  • 1
  • 1
Chaideo
  • 3
  • 4
  • 1
    Can you share sample data from df1? Also your code block to print the data – Anshul Jun 03 '20 at 10:05
  • You numbers are not recognized as numbers by pandas. It uses the general `object` datatype. You can force it to use `float` with the `dtype` argument when creating the dataframe. Can you show the creation and your plot function? – Not_a_programmer Jun 03 '20 at 10:16
  • what kind of plot do you want to draw? – ajay gandhi Jun 03 '20 at 10:24
  • i have two columns name model2 and model3 need to see comparision between these with Manual column.. like model2 with Manual and model3 with Manual. – Chaideo Jun 03 '20 at 10:34
  • @Anshul can you not access the image link i posted if not? let me know – Chaideo Jun 03 '20 at 10:36
  • Images dont help much my friend. It will be helpful for someone who would like to help you to take a look at source input in text/copy-pastable format and also the expected output. – Anshul Jun 03 '20 at 10:38
  • @Not_a_programmer what kind of plot will be best? as i am a beginner i was thinking for bar plot – Chaideo Jun 03 '20 at 11:13
  • @ajaygandhi i was thinking for bar graph – Chaideo Jun 03 '20 at 11:17
  • @Chaideo I'm still not sure what you want to plot. What is x? What is y? Also, how do you create the data? Do you import it? What does the source look like? In general, you can simply do plots with `df.plot()`. – Not_a_programmer Jun 03 '20 at 11:40
  • @Not_a_programmer i want to plot graph for two columns in df1 for model2 and model3, and to check through graph which is best either model2 or model3?? also source is excel macro file ,model 2 and model 3 having this number for eg:1234.5. – Chaideo Jun 03 '20 at 18:40
  • @Chaideo I understand that you want to plot `Model2` and `Model3` on the y-axis, but what is the x-axis? Is it the index. If so, you can simply use `df.plot(y=['Model2', 'Model3'])`. However, your problem is probably that these columns are not recognized as floats. Check [this answer](https://stackoverflow.com/a/28648923/12182316) on how to convert your data. – Not_a_programmer Jun 04 '20 at 08:30
  • @Not_a_programmer x axis as Manual , also tried to convert object into float but throwing error. i have edited the question please check and help. – Chaideo Jun 04 '20 at 09:59
  • @Chaideo It looks like there is a value in your column `Model2` which is also called `Model2`. You can check this with `df1.loc[df1['Model2'] == 'Model2']`. – Not_a_programmer Jun 04 '20 at 10:24

0 Answers0