dataframe in python code example

Example 1: creata daframe python

d = {'col1': [1, 2], 'col2': [3, 4]}
df = pd.DataFrame(data=d)
df

Example 2: create a dataframe python

import numpy as np
import pandas as pd
vect1=np.zeros(10)
vect2=np.ones(10)
df=pd.DataFrame({'col1':vect1,'col2':vect2})

Example 3: dataframein python

import pandas as pd

data = {'First Column Name':  ['First value', 'Second value',...],
        'Second Column Name': ['First value', 'Second value',...],
         ....
        }

df = pd.DataFrame (data, columns = ['First Column Name','Second Column Name',...])

Example 4: pandas dataframe

>>> df2 = pd.DataFrame(np.array([[23, 99, 78], [65, 95, 90], [90, 98, 96]]),
...                    columns=['krish', 'ishwar', 'raj'])
>>> df2
   a  b  c
0  1  2  3
1  4  5  6
2  7  8  9

Example 5: define a dataframe using pandas

In [2]: df = pd.DataFrame(
   ...:     {
   ...:         "Name": [
   ...:             "Braund, Mr. Owen Harris",
   ...:             "Allen, Mr. William Henry",
   ...:             "Bonnell, Miss. Elizabeth",
   ...:         ],
   ...:         "Age": [22, 35, 58],
   ...:         "Sex": ["male", "male", "female"],
   ...:     }
   ...: )
   ...: 

In [3]: df
Out[3]: 
                       Name  Age     Sex
0   Braund, Mr. Owen Harris   22    male
1  Allen, Mr. William Henry   35    male
2  Bonnell, Miss. Elizabeth   58  female

Example 6: pd dataframe

df = pd.DataFrame ({"x": x_array, "y": y_array})