I have a dataframe with only data . I have hardocded headers in my code. How do I append data to the headers with the data already in data frame. data.csv has random data with random columns and I have to pick only certain records with specific filter which I am doing by iloc and assigning to data frame df_NEW. below is my code:
import pandas as pd
df=pd.read.csv("C:\\users\\data.csv")
headers=['col1','col2','col3','col4','col5']
df_NEW=df[df.iloc[:,3]=='NEW']
df_NEW_final=pd.DataFrame(df_NEW,columns=header)
I know how to append the headers to the data while reading csv. But here, I have to read csv and assign the data based on iloc filter to one data frame and then the result we get from df_NEW, we have to add the columns to this data frame.
df_NEW_final=pd.DataFrame(df_NEW,columns=header)
above line gives me only headers but without data.
Also, I have 46 headers and only few columns with values . If data is not present then that column should go as blank.
How do i do this ?