I'm trying to read one csv file and write specific rows of that file into another file.
The code runs fine, but the output is not formatted properly:
import pandas as pd
import sys
f = open("output.csv", 'w')
sys.stdout = f
df = pd.read_csv('original_file.csv', low_memory=False)
print df[(df.name == 'fullName')]
print df[(df.name == 'LastName')]
f.close()
In the original file there are multiple columns, all filled with strings. I want to print every row where the name column equals fullName and LastName. However output.csv has all of the data crammed into a single column.
I'm doing all of this on Ubuntu using Vim. I don't know if that would make a difference.
How do I get the output data to write to its corresponding column in output.csv?
to_csvmethod ? pandas.pydata.org/pandas-docs/stable/generated/…print df[(df.name == 'fullName')|(df.name == 'LastName')]fullNameand such. I'm sure there is a way, but I'm not familiar enough with pandas to find it.