I have this CSV file and I want to remove the other headers in the file and just leave the top header then remove the other column that is duplicate or already existing in the top header. If the column is not yet existing in the top header I need to create a new column for that. Is that possible in Python? Please see the image link below.
CodePudding user response:
Looks like multi-Index df to me.
I will just suggest one approch pls, Try it & Let me know if doesn't work.
Split your df into df into 2 using pandas.DataFrame.xs
import pandas as pd
df = pd.read_csv("jellobeann.csv")
df1, df2 = df.xs(0),df.xs(1)
Then conact them on common column names. As your requiremnt if there is no column name it will create one fill empty with Nan
final = pd.concat([df1,df2],ignore_index=True)
final.to_csv("new_csv.csv", encoding='utf-8')
print(final)
CodePudding user response:
this is the sheetal rajput famous anchor website please check now! Official - Sheetal Rajput (https://sheetalrajputofficial.com/)