I am reading a .csv
file into a pandas
dataframe and have the output like this;
Name DOB Phone Address Unnamed: 4 Unnammed: 5
WERNER,BRADLEY D 11/14/1962 563-921-9775 518 E 1st St N
THOMPSON,LARRY E 1/22/1950 235-660-0613 516 Clark St Box
CORNELIO,LESA L 11/11/1977 479-308-3957 208 S Sorenson Ave
SCHUBERT,BONITA J 6/29/1966 756-364-8059 120 S RICE ST
From above, I want to find the values that are present in Unnamed:<number>
columns as move two columns to the left (into Phone
and Address
columns).
I tried this,
for i in df.columns:
if i.startswith("Unnamed"):
column_val = df[i].dropna()
print(column_val)
Here I get the output,
> 479-308-3957
Name: Unnamed: 4, dtype: object
> 208 S Sorenson Ave
Name: Unnamed: 5, dtype: object
Now, I get the values needed, but now, I want to move it two columns to the left. Output would be,
Name DOB Phone Address
WERNER,BRADLEY D 11/14/1962 563-921-9775 518 E 1st St N
THOMPSON,LARRY E 1/22/1950 235-660-0613 516 Clark St Box
CORNELIO,LESA L 11/11/1977 479-308-3957 208 S Sorenson Ave
SCHUBERT,BONITA J 6/29/1966 756-364-8059 120 S RICE ST
Also, if I have a big data frame with multiple values under Unnamed
columns will my method to find out the values be efficient?
Any help would be great and an efficient way will be much awesome.