Search code examples
pythondataframedata-analysis

How do I create a table by using DataFrame & Index


I'm new to Python & want to learn and use it for Data Analysis/Data Science. I'm getting a syntax error.

import pandas as pd
pd.DataFrame({‘Q1’:[13000,100,150],‘Q2’:[14000,140,200],‘Q3’:[15000,140,250],‘Q4’[16000,180,300]},index= [‘Imp’,‘Click’,‘Eng’])

enter image description here enter image description here


Solution

  • I think the issue was with the Quotes that you used in the dataframe.

    import pandas as pd
    
    
    df = pd.DataFrame({"Q1":[13000,100,150],"Q2":[14000,140,200],"Q3":[15000,140,250],"Q4":[16000,180,300]},index= ["Imp","Click","Eng"])
    
    print(df)
    
              Q1     Q2     Q3     Q4
    Imp    13000  14000  15000  16000
    Click    100    140    140    180
    Eng      150    200    250    300