Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python pandas create an empty dataframe with columns and data types

#Create empty DataFrame with specific column names & types
df = pd.DataFrame({'Courses': pd.Series(dtype='str'),
                   'Fee': pd.Series(dtype='int'),
                   'Duration': pd.Series(dtype='str'),
                   'Discount': pd.Series(dtype='float')})
# Using NumPy
dtypes = np.dtype(
    [
        ("Courses", str),
        ("Fee", int),
        ("Duration", str),
        ("Discount", float),
        ('date',np.datetime64)
    ]
)
df = pd.DataFrame(np.empty(0, dtype=dtypes))
Source by sparkbyexamples.com #
 
PREVIOUS NEXT
Tagged: #python #pandas #create #empty #dataframe #columns #data #types
ADD COMMENT
Topic
Name
8+6 =