I have a dataframe in pandas which I would like to write to a CSV file. I am doing this using: And getting the following error: Is there any way to get around this easily (i.e. I have unicode characters in my data frame)? And is there a way to write to a tab delimited file instead of a CSV
Tag: dataframe
How to read a .xlsx file using the pandas Library in iPython?
I want to read a .xlsx file using the Pandas Library of python and port the data to a postgreSQL table. All I could do up until now is: Now I know that the step got executed successfully, but I want to know how i can parse the excel file that has been read so that I can understand how
How to split a dataframe string column into two columns?
I have a data frame with one (string) column and I’d like to split it into two (string) columns, with one column header as ‘fips’ and the other ‘row’ My dataframe df looks like this: I do not know how to use df.row.str[:] to achieve my goal of splitting the row cell. I can use df[‘fips’] = hello to add
python pandas extract unique dates from time series
I have a DataFrame which contains a lot of intraday data, the DataFrame has several days of data, dates are not continuous. How can I extract the unique date in the datetime format from the above DataFrame? To have result like [2012-10-08, 2012-10-10] Answer If you have a Series like: where each object is a Timestamp: you can get only
How to drop rows of Pandas DataFrame whose value in a certain column is NaN
I have this DataFrame and want only the records whose EPS column is not NaN: …i.e. something like df.drop(….) to get this resulting dataframe: How do I do that? Answer Don’t drop, just take the rows where EPS is not NA:
How to add a new column to an existing DataFrame?
I have the following indexed DataFrame with named columns and rows not- continuous numbers: I would like to add a new column, ‘e’, to the existing data frame and do not want to change anything in the data frame (i.e., the new column always has the same length as the DataFrame). How can I add column e to the above
pandas: filter rows of DataFrame with operator chaining
Most operations in pandas can be accomplished with operator chaining (groupby, aggregate, apply, etc), but the only way I’ve found to filter rows is via normal bracket indexing This is unappealing as it requires I assign df to a variable before being able to filter on its values. Is there something more like the following? Answer I’m not entirely sure
Create a Pandas Dataframe by appending one row at a time
How do I create an empty DataFrame, then add rows, one by one? I created an empty DataFrame: Then I can add a new row at the end and fill a single field with: It works for only one field at a time. What is a better way to add new row to df? Answer You can use df.loc[i], where