csv

Read specific (non-consecutive) rows from csv

半城伤御伤魂 提交于 2021-01-27 13:07:05
问题 I have a large csv file and would like to read only certain lines, defined by a vector of row numbers to be read. Is there any way to read these rows without reading the whole csv into memory? The only solutions I've found seem to allow reading consecutive lines (e.g. lines 2-100). 回答1: A simple example of how you might combine the sed approach I linked to into an R function: read_rows <- function(file,rows,...){ tmp <- tempfile() row_cmd <- paste(paste(rows,"p",sep = ""),collapse = ";") cmd

How do i add column header, in the second row in a pandas dataframe?

旧时模样 提交于 2021-01-27 12:11:12
问题 I have a data frame frame from pandas and now I want to add columns names, but only for the second row. Here is an example of my previous output: Desired output: My code: data_line=open("file1.txt", mode="r") lines=[] for line in data_line: lines.append(line) for i, line in enumerate(lines): # print('{}={}'.format(i+1, line.strip())) file1_header=lines[0] num_line=1 Dictionary_File1={} Value_File1= data_type[0:6] Value_File1_short=[] i=1 for element in Value_File1: type=element.split(',')

How do i add column header, in the second row in a pandas dataframe?

心不动则不痛 提交于 2021-01-27 12:09:29
问题 I have a data frame frame from pandas and now I want to add columns names, but only for the second row. Here is an example of my previous output: Desired output: My code: data_line=open("file1.txt", mode="r") lines=[] for line in data_line: lines.append(line) for i, line in enumerate(lines): # print('{}={}'.format(i+1, line.strip())) file1_header=lines[0] num_line=1 Dictionary_File1={} Value_File1= data_type[0:6] Value_File1_short=[] i=1 for element in Value_File1: type=element.split(',')

PostgreSQL - \copy command

天大地大妈咪最大 提交于 2021-01-27 11:25:45
问题 I tried the above code. I manage to Compile. However, when I run, it give me error: Exception in thread "main" org.postgresql.util.PSQLException: ERROR: syntax error at or near "\" Position: 1 It shows that the query that I run is wrong: String query ="\\COPY tmp from 'E:\\load.csv' delimiter ',';"; The System.out.println for the query is: query string: \COPY tmp from 'E:\load.csv' delimiter ','; I run the query : \COPY tmp from 'E:\load.csv' delimiter ','; in PostgresSQL client, it works.

PostgreSQL - \copy command

亡梦爱人 提交于 2021-01-27 11:24:13
问题 I tried the above code. I manage to Compile. However, when I run, it give me error: Exception in thread "main" org.postgresql.util.PSQLException: ERROR: syntax error at or near "\" Position: 1 It shows that the query that I run is wrong: String query ="\\COPY tmp from 'E:\\load.csv' delimiter ',';"; The System.out.println for the query is: query string: \COPY tmp from 'E:\load.csv' delimiter ','; I run the query : \COPY tmp from 'E:\load.csv' delimiter ','; in PostgresSQL client, it works.

how to merge two cell in csv file

守給你的承諾、 提交于 2021-01-27 10:26:28
问题 how to merge two cell in csv file like as excel I want to merge two cell in csv file file as Header Id Name mobileNo Sub-Header id first Name last Name countryCode MobNumber 回答1: This is not possible A comma-separated values (CSV) file stores tabular data (numbers and text) in plain text. It is just data, with no attached formatting or knowledge of how the cells should be merged when the data is imported. You could use a script maybe like python to merge them, refer this link https://dzone

how to merge two cell in csv file

非 Y 不嫁゛ 提交于 2021-01-27 10:20:28
问题 how to merge two cell in csv file like as excel I want to merge two cell in csv file file as Header Id Name mobileNo Sub-Header id first Name last Name countryCode MobNumber 回答1: This is not possible A comma-separated values (CSV) file stores tabular data (numbers and text) in plain text. It is just data, with no attached formatting or knowledge of how the cells should be merged when the data is imported. You could use a script maybe like python to merge them, refer this link https://dzone

how to merge two cell in csv file

帅比萌擦擦* 提交于 2021-01-27 10:19:05
问题 how to merge two cell in csv file like as excel I want to merge two cell in csv file file as Header Id Name mobileNo Sub-Header id first Name last Name countryCode MobNumber 回答1: This is not possible A comma-separated values (CSV) file stores tabular data (numbers and text) in plain text. It is just data, with no attached formatting or knowledge of how the cells should be merged when the data is imported. You could use a script maybe like python to merge them, refer this link https://dzone

Pandas read_csv, reading a boolean with missing values specified as an int

只愿长相守 提交于 2021-01-27 07:10:32
问题 I am trying to import a csv into a pandas dataframe. I have boolean variables denoted with 1's and 0's, where missing values are identified with a -9. When I try to specify the dtype as boolean, I get a host of different errors, depending on what I try. Sample data: test.csv var1, var2 0, 0 0, 1 1, 3 -9, 0 0, 2 1, 7 I try to specify the dtype as I import: dtype_dict = {'var1':'bool','var2':'int'} nan_dict = {'var1':[-9]} foo = pd.read_csv('test.csv',dtype=dtype_dict, na_values=nan_dict) I get

Spark 2.0.0: SparkR CSV Import

依然范特西╮ 提交于 2021-01-27 06:48:37
问题 I am trying to read a csv file into SparkR (running Spark 2.0.0) - & trying to experiment with the newly added features. Using RStudio here. I am getting an error while "reading" the source file. My code: Sys.setenv(SPARK_HOME = "C:/spark-2.0.0-bin-hadoop2.6") library(SparkR, lib.loc = c(file.path(Sys.getenv("SPARK_HOME"), "R", "lib"))) sparkR.session(master = "local[*]", appName = "SparkR") df <- loadDF("F:/file.csv", "csv", header = "true") I get an error at at the loadDF function. The